diff Core/HttpServer/HttpOutput.cpp @ 2954:d924f9bb61cc

taking advantage of details in OrthancException
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 03 Dec 2018 14:35:34 +0100
parents 9d277f8ad698
children 4e43e67f8ecf
line wrap: on
line diff
--- a/Core/HttpServer/HttpOutput.cpp	Mon Dec 03 11:49:39 2018 +0100
+++ b/Core/HttpServer/HttpOutput.cpp	Mon Dec 03 14:35:34 2018 +0100
@@ -151,8 +151,9 @@
       }
       else
       {
-        LOG(ERROR) << "Because of keep-alive connections, the entire body must be sent at once or Content-Length must be given";
-        throw OrthancException(ErrorCode_BadSequenceOfCalls);
+        throw OrthancException(ErrorCode_BadSequenceOfCalls,
+                               "Because of keep-alive connections, the entire body must "
+                               "be sent at once or Content-Length must be given");
       }
     }
 
@@ -198,8 +199,8 @@
     if (hasContentLength_ &&
         contentPosition_ + length > contentLength_)
     {
-      LOG(ERROR) << "The body size exceeds what was declared with SetContentSize()";
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+      throw OrthancException(ErrorCode_BadSequenceOfCalls,
+                             "The body size exceeds what was declared with SetContentSize()");
     }
 
     if (length > 0)
@@ -233,15 +234,15 @@
         }
         else
         {
-          LOG(ERROR) << "The body size has not reached what was declared with SetContentSize()";
-          throw OrthancException(ErrorCode_BadSequenceOfCalls);
+          throw OrthancException(ErrorCode_BadSequenceOfCalls,
+                                 "The body size has not reached what was declared with SetContentSize()");
         }
 
         break;
 
       case State_WritingMultipart:
-        LOG(ERROR) << "Cannot invoke CloseBody() with multipart outputs";
-        throw OrthancException(ErrorCode_BadSequenceOfCalls);
+        throw OrthancException(ErrorCode_BadSequenceOfCalls,
+                               "Cannot invoke CloseBody() with multipart outputs");
 
       case State_Done:
         return;  // Ignore
@@ -296,8 +297,8 @@
         status == HttpStatus_401_Unauthorized ||
         status == HttpStatus_405_MethodNotAllowed)
     {
-      LOG(ERROR) << "Please use the dedicated methods to this HTTP status code in HttpOutput";
-      throw OrthancException(ErrorCode_ParameterOutOfRange);
+      throw OrthancException(ErrorCode_ParameterOutOfRange,
+                             "Please use the dedicated methods to this HTTP status code in HttpOutput");
     }
     
     stateMachine_.SetHttpStatus(status);
@@ -408,8 +409,8 @@
 
     if (keepAlive_)
     {
-      LOG(ERROR) << "Multipart answers are not implemented together with keep-alive connections";
-      throw OrthancException(ErrorCode_NotImplemented);
+      throw OrthancException(ErrorCode_NotImplemented,
+                             "Multipart answers are not implemented together with keep-alive connections");
     }
 
     if (state_ != State_WritingHeader)
@@ -433,9 +434,9 @@
     {
       if (!Toolbox::StartsWith(*it, "Set-Cookie: "))
       {
-        LOG(ERROR) << "The only headers that can be set in multipart answers "
-                   << "are Set-Cookie (here: " << *it << " is set)";
-        throw OrthancException(ErrorCode_BadSequenceOfCalls);
+        throw OrthancException(ErrorCode_BadSequenceOfCalls,
+                               "The only headers that can be set in multipart answers "
+                               "are Set-Cookie (here: " + *it + " is set)");
       }
 
       header += *it;