Mercurial > hg > orthanc
changeset 2952:4ceb9bf7b00c
added details string in OrthancException
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 03 Dec 2018 11:46:04 +0100 |
parents | 65b20d922e10 |
children | 210d5afd8f2b |
files | Core/OrthancException.h OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/main.cpp Resources/ErrorCodes.json |
diffstat | 4 files changed, 78 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- 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 <stdint.h> #include <string> -#include "Enumerations.h" +#include <memory> 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<std::string> 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(); + } + } }; }
--- 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
--- 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); }
--- 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)" },