# HG changeset patch # User Sebastien Jodogne # Date 1443192425 -7200 # Node ID 9f34ebfaf2c9b01573d9a9498269bbaeaf7809f7 # Parent 8040d56cb0b37d3b2ec1cc043a8c04a2d050f0e3 refactoring diff -r 8040d56cb0b3 -r 9f34ebfaf2c9 OrthancServer/main.cpp --- a/OrthancServer/main.cpp Fri Sep 25 16:24:13 2015 +0200 +++ b/OrthancServer/main.cpp Fri Sep 25 16:47:05 2015 +0200 @@ -327,6 +327,23 @@ HttpMethod method, const char* uri) { + { + bool isPlugin = false; + +#if ORTHANC_PLUGINS_ENABLED == 1 + if (plugins_ != NULL) + { + plugins_->GetErrorDictionary().LogError(exception); + isPlugin = true; + } +#endif + + if (!isPlugin) + { + LOG(ERROR) << "Exception in the HTTP handler: " << exception.What(); + } + } + Json::Value message = Json::objectValue; ErrorCode errorCode = exception.GetErrorCode(); HttpStatus httpStatus = exception.GetHttpStatus(); @@ -338,8 +355,6 @@ 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; } @@ -347,7 +362,6 @@ if (!isPlugin) { - LOG(ERROR) << "Exception in the HTTP handler: " << exception.What(); message["Message"] = exception.What(); } } diff -r 8040d56cb0b3 -r 9f34ebfaf2c9 Plugins/Engine/PluginsErrorDictionary.cpp --- a/Plugins/Engine/PluginsErrorDictionary.cpp Fri Sep 25 16:24:13 2015 +0200 +++ b/Plugins/Engine/PluginsErrorDictionary.cpp Fri Sep 25 16:47:05 2015 +0200 @@ -41,6 +41,7 @@ #include "PluginsEnumerations.h" #include "PluginsManager.h" +#include "../../Core/Logging.h" #include @@ -87,6 +88,26 @@ } + void PluginsErrorDictionary::LogError(const OrthancException& exception) + { + if (exception.GetErrorCode() >= ErrorCode_START_PLUGINS) + { + boost::mutex::scoped_lock lock(mutex_); + Errors::const_iterator error = errors_.find(static_cast(exception.GetErrorCode())); + + if (error != errors_.end()) + { + LOG(ERROR) << "Error code " << error->second->pluginCode_ + << " inside plugin \"" << error->second->pluginName_ + << "\": " << error->second->message_; + return; + } + } + + LOG(ERROR) << "Exception inside the plugin engine: " << exception.What(); + } + + bool PluginsErrorDictionary::Format(Json::Value& message, /* out */ HttpStatus& httpStatus, /* out */ const OrthancException& exception) diff -r 8040d56cb0b3 -r 9f34ebfaf2c9 Plugins/Engine/PluginsErrorDictionary.h --- a/Plugins/Engine/PluginsErrorDictionary.h Fri Sep 25 16:24:13 2015 +0200 +++ b/Plugins/Engine/PluginsErrorDictionary.h Fri Sep 25 16:47:05 2015 +0200 @@ -74,6 +74,8 @@ uint16_t httpStatus, const char* message); + void LogError(const OrthancException& exception); + bool Format(Json::Value& message, /* out */ HttpStatus& httpStatus, /* out */ const OrthancException& exception); diff -r 8040d56cb0b3 -r 9f34ebfaf2c9 Plugins/Samples/Basic/Plugin.c --- a/Plugins/Samples/Basic/Plugin.c Fri Sep 25 16:24:13 2015 +0200 +++ b/Plugins/Samples/Basic/Plugin.c Fri Sep 25 16:47:05 2015 +0200 @@ -25,6 +25,8 @@ static OrthancPluginContext* context = NULL; +static OrthancPluginErrorCode c1; + ORTHANC_PLUGINS_API int32_t Callback1(OrthancPluginRestOutput* output, const char* url, @@ -214,6 +216,8 @@ const char* url, const OrthancPluginHttpRequest* request) { + return c1; + const char* pathLocator = "\"Path\" : \""; char info[1024]; char *id, *eos; @@ -401,6 +405,8 @@ sprintf(info, "[ \"STORESCP\", \"localhost\", 2000 ]"); OrthancPluginRestApiPut(context, &tmp, "/modalities/demo", info, strlen(info)); + c1 = OrthancPluginRegisterErrorCode(context, 4, 402, "Hello world"); + return 0; }