Mercurial > hg > orthanc
changeset 1650:9f34ebfaf2c9
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 25 Sep 2015 16:47:05 +0200 |
parents | 8040d56cb0b3 |
children | 2e692c83e2f3 |
files | OrthancServer/main.cpp Plugins/Engine/PluginsErrorDictionary.cpp Plugins/Engine/PluginsErrorDictionary.h Plugins/Samples/Basic/Plugin.c |
diffstat | 4 files changed, 46 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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(); } }
--- 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 <memory> @@ -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<int32_t>(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)
--- 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);
--- 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; }