diff OrthancServer/main.cpp @ 1649:8040d56cb0b3

New function "OrthancPluginRegisterErrorCode()" to declare custom error codes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 25 Sep 2015 16:24:13 +0200
parents 1558b3226b18
children 9f34ebfaf2c9
line wrap: on
line diff
--- a/OrthancServer/main.cpp	Fri Sep 25 11:33:55 2015 +0200
+++ b/OrthancServer/main.cpp	Fri Sep 25 16:24:13 2015 +0200
@@ -327,42 +327,47 @@
                       HttpMethod method,
                       const char* uri)
   {
-    if (!describeErrors_)
-    {
-      output.SendStatus(exception.GetHttpStatus());
-      return;
-    }
-
     Json::Value message = Json::objectValue;
-    message["Method"] = EnumerationToString(method);
-    message["Uri"] = uri;
-
     ErrorCode errorCode = exception.GetErrorCode();
     HttpStatus httpStatus = exception.GetHttpStatus();
 
-    bool isPlugin = false;
+    {
+      bool isPlugin = false;
 
 #if ORTHANC_PLUGINS_ENABLED == 1
-    if (plugins_ != NULL &&
-        plugins_->GetErrorDictionary().Format(message, httpStatus, exception))
-    {
-      errorCode = ErrorCode_Plugin;
-      isPlugin = true;
-    }
+      if (plugins_ != NULL &&
+          plugins_->GetErrorDictionary().Format(message, httpStatus, exception))
+      {
+        LOG(ERROR) << "Error code " << message["PluginCode"].asInt() << " inside plugin \"" 
+                   << message["PluginName"].asString() << "\": " << message["Message"].asString();
+        errorCode = ErrorCode_Plugin;
+        isPlugin = true;
+      }
 #endif
 
-    if (!isPlugin)
-    {
-      message["Message"] = exception.What();
+      if (!isPlugin)
+      {
+        LOG(ERROR) << "Exception in the HTTP handler: " << exception.What();
+        message["Message"] = exception.What();
+      }
     }
 
-    message["HttpError"] = EnumerationToString(httpStatus);
-    message["HttpStatus"] = httpStatus;
-    message["OrthancError"] = EnumerationToString(errorCode);
-    message["OrthancStatus"] = errorCode;
+    if (!describeErrors_)
+    {
+      output.SendStatus(httpStatus);
+    }
+    else
+    {
+      message["Method"] = EnumerationToString(method);
+      message["Uri"] = uri;
+      message["HttpError"] = EnumerationToString(httpStatus);
+      message["HttpStatus"] = httpStatus;
+      message["OrthancError"] = EnumerationToString(errorCode);
+      message["OrthancStatus"] = errorCode;
 
-    std::string info = message.toStyledString();
-    output.SendStatus(httpStatus, info);
+      std::string info = message.toStyledString();
+      output.SendStatus(httpStatus, info);
+    }
   }
 };