comparison Core/OrthancException.h @ 2952:4ceb9bf7b00c

added details string in OrthancException
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 03 Dec 2018 11:46:04 +0100
parents 878b59270859
children d924f9bb61cc
comparison
equal deleted inserted replaced
2951:65b20d922e10 2952:4ceb9bf7b00c
31 **/ 31 **/
32 32
33 33
34 #pragma once 34 #pragma once
35 35
36 #include "Enumerations.h"
37 #include "Logging.h"
38
36 #include <stdint.h> 39 #include <stdint.h>
37 #include <string> 40 #include <string>
38 #include "Enumerations.h" 41 #include <memory>
39 42
40 namespace Orthanc 43 namespace Orthanc
41 { 44 {
42 class OrthancException 45 class OrthancException
43 { 46 {
44 protected: 47 private:
48 OrthancException(); // Forbidden
49
50 OrthancException& operator= (const OrthancException&); // Forbidden
51
45 ErrorCode errorCode_; 52 ErrorCode errorCode_;
46 HttpStatus httpStatus_; 53 HttpStatus httpStatus_;
47 54
55 // New in Orthanc 1.4.3
56 std::auto_ptr<std::string> details_;
57
48 public: 58 public:
59 OrthancException(const OrthancException& other) :
60 errorCode_(other.errorCode_),
61 httpStatus_(other.httpStatus_)
62 {
63 if (other.details_.get() != NULL)
64 {
65 details_.reset(new std::string(*other.details_));
66 }
67 }
68
49 explicit OrthancException(ErrorCode errorCode) : 69 explicit OrthancException(ErrorCode errorCode) :
50 errorCode_(errorCode), 70 errorCode_(errorCode),
51 httpStatus_(ConvertErrorCodeToHttpStatus(errorCode)) 71 httpStatus_(ConvertErrorCodeToHttpStatus(errorCode))
52 { 72 {
53 } 73 }
54 74
55 OrthancException(ErrorCode errorCode, 75 OrthancException(ErrorCode errorCode,
76 const std::string& details) :
77 errorCode_(errorCode),
78 httpStatus_(ConvertErrorCodeToHttpStatus(errorCode)),
79 details_(new std::string(details))
80 {
81 LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details;
82 }
83
84 OrthancException(ErrorCode errorCode,
56 HttpStatus httpStatus) : 85 HttpStatus httpStatus) :
57 errorCode_(errorCode), 86 errorCode_(errorCode),
58 httpStatus_(httpStatus) 87 httpStatus_(httpStatus)
59 { 88 {
89 }
90
91 OrthancException(ErrorCode errorCode,
92 HttpStatus httpStatus,
93 const std::string& details) :
94 errorCode_(errorCode),
95 httpStatus_(httpStatus),
96 details_(new std::string(details))
97 {
98 LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details;
60 } 99 }
61 100
62 ErrorCode GetErrorCode() const 101 ErrorCode GetErrorCode() const
63 { 102 {
64 return errorCode_; 103 return errorCode_;
71 110
72 const char* What() const 111 const char* What() const
73 { 112 {
74 return EnumerationToString(errorCode_); 113 return EnumerationToString(errorCode_);
75 } 114 }
115
116 bool HasDetails() const
117 {
118 return details_.get() != NULL;
119 }
120
121 const char* GetDetails() const
122 {
123 if (details_.get() == NULL)
124 {
125 return "";
126 }
127 else
128 {
129 return details_->c_str();
130 }
131 }
76 }; 132 };
77 } 133 }