# HG changeset patch # User Sebastien Jodogne # Date 1543833964 -3600 # Node ID 4ceb9bf7b00c5899b3df5c45c759bfaec6f0a636 # Parent 65b20d922e1039d3e2da75492b401fc84463e2e6 added details string in OrthancException diff -r 65b20d922e10 -r 4ceb9bf7b00c Core/OrthancException.h --- a/Core/OrthancException.h Mon Dec 03 10:02:25 2018 +0100 +++ b/Core/OrthancException.h Mon Dec 03 11:46:04 2018 +0100 @@ -33,19 +33,39 @@ #pragma once +#include "Enumerations.h" +#include "Logging.h" + #include #include -#include "Enumerations.h" +#include namespace Orthanc { class OrthancException { - protected: + private: + OrthancException(); // Forbidden + + OrthancException& operator= (const OrthancException&); // Forbidden + ErrorCode errorCode_; HttpStatus httpStatus_; + // New in Orthanc 1.4.3 + std::auto_ptr details_; + public: + OrthancException(const OrthancException& other) : + errorCode_(other.errorCode_), + httpStatus_(other.httpStatus_) + { + if (other.details_.get() != NULL) + { + details_.reset(new std::string(*other.details_)); + } + } + explicit OrthancException(ErrorCode errorCode) : errorCode_(errorCode), httpStatus_(ConvertErrorCodeToHttpStatus(errorCode)) @@ -53,12 +73,31 @@ } OrthancException(ErrorCode errorCode, + const std::string& details) : + errorCode_(errorCode), + httpStatus_(ConvertErrorCodeToHttpStatus(errorCode)), + details_(new std::string(details)) + { + LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details; + } + + OrthancException(ErrorCode errorCode, HttpStatus httpStatus) : errorCode_(errorCode), httpStatus_(httpStatus) { } + OrthancException(ErrorCode errorCode, + HttpStatus httpStatus, + const std::string& details) : + errorCode_(errorCode), + httpStatus_(httpStatus), + details_(new std::string(details)) + { + LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details; + } + ErrorCode GetErrorCode() const { return errorCode_; @@ -73,5 +112,22 @@ { return EnumerationToString(errorCode_); } + + bool HasDetails() const + { + return details_.get() != NULL; + } + + const char* GetDetails() const + { + if (details_.get() == NULL) + { + return ""; + } + else + { + return details_->c_str(); + } + } }; } diff -r 65b20d922e10 -r 4ceb9bf7b00c OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Mon Dec 03 10:02:25 2018 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Mon Dec 03 11:46:04 2018 +0100 @@ -297,13 +297,11 @@ tag != DICOM_TAG_STUDY_TIME && dicom.HasTag(tag)) { - LOG(ERROR) << EnumerationToString(ErrorCode_CreateDicomOverrideTag) << ": " << name; - throw OrthancException(ErrorCode_CreateDicomOverrideTag); + throw OrthancException(ErrorCode_CreateDicomOverrideTag, name); } if (tag == DICOM_TAG_PIXEL_DATA) { - LOG(ERROR) << EnumerationToString(ErrorCode_CreateDicomUseContent); throw OrthancException(ErrorCode_CreateDicomUseContent); } else diff -r 65b20d922e10 -r 4ceb9bf7b00c OrthancServer/main.cpp --- a/OrthancServer/main.cpp Mon Dec 03 10:02:25 2018 +0100 +++ b/OrthancServer/main.cpp Mon Dec 03 11:46:04 2018 +0100 @@ -482,6 +482,11 @@ message["OrthancError"] = EnumerationToString(errorCode); message["OrthancStatus"] = errorCode; + if (exception.HasDetails()) + { + message["Details"] = exception.GetDetails(); + } + std::string info = message.toStyledString(); output.SendStatus(httpStatus, info); } diff -r 65b20d922e10 -r 4ceb9bf7b00c Resources/ErrorCodes.json --- a/Resources/ErrorCodes.json Mon Dec 03 10:02:25 2018 +0100 +++ b/Resources/ErrorCodes.json Mon Dec 03 11:46:04 2018 +0100 @@ -421,37 +421,44 @@ "Description": "Cannot store an instance" }, { - "Code": 2019, + "Code": 2019, + "HttpStatus": 400, "Name": "CreateDicomNotString", "Description": "Only string values are supported when creating DICOM instances" }, { - "Code": 2020, + "Code": 2020, + "HttpStatus": 400, "Name": "CreateDicomOverrideTag", "Description": "Trying to override a value inherited from a parent module" }, { - "Code": 2021, + "Code": 2021, + "HttpStatus": 400, "Name": "CreateDicomUseContent", "Description": "Use \\\"Content\\\" to inject an image into a new DICOM instance" }, { - "Code": 2022, + "Code": 2022, + "HttpStatus": 400, "Name": "CreateDicomNoPayload", "Description": "No payload is present for one instance in the series" }, { - "Code": 2023, + "Code": 2023, + "HttpStatus": 400, "Name": "CreateDicomUseDataUriScheme", "Description": "The payload of the DICOM instance must be specified according to Data URI scheme" }, { - "Code": 2024, + "Code": 2024, + "HttpStatus": 400, "Name": "CreateDicomBadParent", "Description": "Trying to attach a new DICOM instance to an inexistent resource" }, { - "Code": 2025, + "Code": 2025, + "HttpStatus": 400, "Name": "CreateDicomParentIsInstance", "Description": "Trying to attach a new DICOM instance to an instance (must be a series, study or patient)" },