# HG changeset patch # User Sebastien Jodogne # Date 1543946199 -3600 # Node ID 74a5a7fd6e0ea39afdac035503517f184d7379b3 # Parent 7364415851ac51819cb2c4c6fb22ce38e7c2c0d9 log flag to OrthancPluginSetHttpErrorDetails diff -r 7364415851ac -r 74a5a7fd6e0e Core/OrthancException.h --- a/Core/OrthancException.h Tue Dec 04 16:43:53 2018 +0100 +++ b/Core/OrthancException.h Tue Dec 04 18:56:39 2018 +0100 @@ -73,13 +73,17 @@ } OrthancException(ErrorCode errorCode, - const std::string& details) : + const std::string& details, + bool log = true) : errorCode_(errorCode), httpStatus_(ConvertErrorCodeToHttpStatus(errorCode)), details_(new std::string(details)) { #if ORTHANC_ENABLE_LOGGING == 1 - LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details; + if (log) + { + LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details; + } #endif } @@ -92,13 +96,17 @@ OrthancException(ErrorCode errorCode, HttpStatus httpStatus, - const std::string& details) : + const std::string& details, + bool log = true) : errorCode_(errorCode), httpStatus_(httpStatus), details_(new std::string(details)) { #if ORTHANC_ENABLE_LOGGING == 1 - LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details; + if (log) + { + LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details; + } #endif } diff -r 7364415851ac -r 74a5a7fd6e0e Plugins/Engine/OrthancPlugins.cpp --- a/Plugins/Engine/OrthancPlugins.cpp Tue Dec 04 16:43:53 2018 +0100 +++ b/Plugins/Engine/OrthancPlugins.cpp Tue Dec 04 18:56:39 2018 +0100 @@ -324,10 +324,12 @@ private: HttpOutput& output_; std::auto_ptr errorDetails_; + bool logDetails_; public: PluginHttpOutput(HttpOutput& output) : - output_(output) + output_(output), + logDetails_(false) { } @@ -336,9 +338,11 @@ return output_; } - void SetErrorDetails(const std::string& details) + void SetErrorDetails(const std::string& details, + bool logDetails) { errorDetails_.reset(new std::string(details)); + logDetails_ = logDetails; } bool HasErrorDetails() const @@ -346,6 +350,11 @@ return errorDetails_.get() != NULL; } + bool IsLogDetails() const + { + return logDetails_; + } + const std::string& GetErrorDetails() const { if (errorDetails_.get() == NULL) @@ -1069,7 +1078,8 @@ PImpl::PluginHttpOutput pluginOutput(output); - OrthancPluginErrorCode error = callback->Invoke(pimpl_->restCallbackMutex_, pluginOutput, flatUri, request); + OrthancPluginErrorCode error = callback->Invoke + (pimpl_->restCallbackMutex_, pluginOutput, flatUri, request); if (error == OrthancPluginErrorCode_Success && output.IsWritingMultipart()) @@ -1087,7 +1097,9 @@ if (pluginOutput.HasErrorDetails()) { - throw OrthancException(static_cast(error), pluginOutput.GetErrorDetails()); + throw OrthancException(static_cast(error), + pluginOutput.GetErrorDetails(), + pluginOutput.IsLogDetails()); } else { @@ -1389,8 +1401,9 @@ const _OrthancPluginSetHttpErrorDetails& p = *reinterpret_cast(parameters); - PImpl::PluginHttpOutput* output = reinterpret_cast(p.output); - output->SetErrorDetails(p.details); + PImpl::PluginHttpOutput* output = + reinterpret_cast(p.output); + output->SetErrorDetails(p.details, p.log); } diff -r 7364415851ac -r 74a5a7fd6e0e Plugins/Include/orthanc/OrthancCPlugin.h --- a/Plugins/Include/orthanc/OrthancCPlugin.h Tue Dec 04 16:43:53 2018 +0100 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Tue Dec 04 18:56:39 2018 +0100 @@ -6433,6 +6433,7 @@ { OrthancPluginRestOutput* output; const char* details; + uint8_t log; } _OrthancPluginSetHttpErrorDetails; /** @@ -6449,12 +6450,14 @@ * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). * @param output The HTTP connection to the client application. * @param details The details of the error message. + * @param log Whether to also write the detailed error to the Orthanc logs. * @ingroup REST **/ ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpErrorDetails( OrthancPluginContext* context, OrthancPluginRestOutput* output, - const char* details) + const char* details, + uint8_t log) { _OrthancPluginSetHttpErrorDetails params; params.output = output;