comparison Plugins/Engine/PluginsErrorDictionary.cpp @ 1645:1558b3226b18

IHttpExceptionFormatter
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Sep 2015 15:55:17 +0200
parents 939b921b2c81
children 8040d56cb0b3
comparison
equal deleted inserted replaced
1644:939b921b2c81 1645:1558b3226b18
36 #if ORTHANC_PLUGINS_ENABLED != 1 36 #if ORTHANC_PLUGINS_ENABLED != 1
37 #error The plugin support is disabled 37 #error The plugin support is disabled
38 #endif 38 #endif
39 39
40 40
41
41 #include "PluginsEnumerations.h" 42 #include "PluginsEnumerations.h"
42 #include "PluginsManager.h" 43 #include "PluginsManager.h"
43 44
44 #include <memory> 45 #include <memory>
45 46
59 delete it->second; 60 delete it->second;
60 } 61 }
61 } 62 }
62 63
63 64
64 OrthancPluginErrorCode PluginsErrorDictionary::Register(SharedLibrary& library, 65 OrthancPluginErrorCode PluginsErrorDictionary::Register(const std::string& pluginName,
65 int32_t pluginCode, 66 int32_t pluginCode,
66 const char* description, 67 uint16_t httpStatus,
67 uint16_t httpStatus) 68 const char* description)
68 { 69 {
69 std::auto_ptr<Error> error(new Error); 70 std::auto_ptr<Error> error(new Error);
70 71
72 error->pluginName_ = pluginName;
71 error->pluginCode_ = pluginCode; 73 error->pluginCode_ = pluginCode;
72 error->description_ = description; 74 error->description_ = description;
73 error->httpStatus_ = static_cast<HttpStatus>(httpStatus); 75 error->httpStatus_ = static_cast<HttpStatus>(httpStatus);
74 error->pluginName_ = PluginsManager::GetPluginName(library);
75 76
76 OrthancPluginErrorCode code; 77 OrthancPluginErrorCode code;
77 78
78 { 79 {
79 boost::mutex::scoped_lock lock(mutex_); 80 boost::mutex::scoped_lock lock(mutex_);
84 85
85 return code; 86 return code;
86 } 87 }
87 88
88 89
89 void PluginsErrorDictionary::GetExceptionMessage(Json::Value& message, /* out */ 90 bool PluginsErrorDictionary::Format(Json::Value& message, /* out */
90 HttpStatus& httpStatus, /* out */ 91 HttpStatus& httpStatus, /* out */
91 const OrthancException& exception) 92 const OrthancException& exception)
92 { 93 {
93 bool done = false;
94
95 if (exception.GetErrorCode() >= ErrorCode_START_PLUGINS) 94 if (exception.GetErrorCode() >= ErrorCode_START_PLUGINS)
96 { 95 {
97 boost::mutex::scoped_lock lock(mutex_); 96 boost::mutex::scoped_lock lock(mutex_);
98 Errors::const_iterator error = errors_.find(static_cast<int32_t>(exception.GetErrorCode())); 97 Errors::const_iterator error = errors_.find(static_cast<int32_t>(exception.GetErrorCode()));
99 98
102 httpStatus = error->second->httpStatus_; 101 httpStatus = error->second->httpStatus_;
103 message["PluginName"] = error->second->pluginName_; 102 message["PluginName"] = error->second->pluginName_;
104 message["PluginCode"] = error->second->pluginCode_; 103 message["PluginCode"] = error->second->pluginCode_;
105 message["Message"] = error->second->description_; 104 message["Message"] = error->second->description_;
106 105
107 done = true; 106 return true;
108 } 107 }
109 } 108 }
110 109
111 if (!done) 110 return false;
112 {
113 httpStatus = exception.GetHttpStatus();
114 message["Message"] = exception.What();
115 }
116
117 message["HttpError"] = EnumerationToString(httpStatus);
118 message["HttpStatus"] = httpStatus;
119 message["OrthancError"] = EnumerationToString(exception.GetErrorCode());
120 message["OrthancStatus"] = exception.GetErrorCode();
121 } 111 }
122
123 } 112 }