annotate Core/OrthancException.h @ 3530:b26b6ea27648

endianness to string
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 02 Oct 2019 11:13:32 +0200
parents 4e43e67f8ecf
children 94f4a18a79cc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1644
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
4 * Department, University Hospital of Liege, Belgium
3060
4e43e67f8ecf preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2988
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
11 *
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
12 * In addition, as a special exception, the copyright holders of this
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
13 * program give permission to link the code of its release with the
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
16 * the linked executables. You must obey the GNU General Public License
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
20 * you do not wish to do so, delete this exception statement from your
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
21 * version. If you delete this exception statement from all source files
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
22 * in the program, then also delete it here.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #pragma once
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
2952
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
36 #include "Enumerations.h"
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
37 #include "Logging.h"
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
38
1643
87c77b9b3679 provision for error codes in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
39 #include <stdint.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <string>
2952
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
41 #include <memory>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
43 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
45 class OrthancException
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
2952
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
47 private:
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
48 OrthancException(); // Forbidden
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
49
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
50 OrthancException& operator= (const OrthancException&); // Forbidden
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
51
1643
87c77b9b3679 provision for error codes in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
52 ErrorCode errorCode_;
1575
f8aae45011c9 exceptions now carry HTTP status
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
53 HttpStatus httpStatus_;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
2988
9cc3d40e389b Orthanc 1.4.3 is now known as 1.5.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2960
diff changeset
55 // New in Orthanc 1.5.0
2952
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
56 std::auto_ptr<std::string> details_;
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
57
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
58 public:
2952
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
59 OrthancException(const OrthancException& other) :
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
60 errorCode_(other.errorCode_),
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
61 httpStatus_(other.httpStatus_)
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
62 {
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
63 if (other.details_.get() != NULL)
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
64 {
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
65 details_.reset(new std::string(*other.details_));
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
66 }
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
67 }
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
68
2223
29689b30f9ae cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
69 explicit OrthancException(ErrorCode errorCode) :
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1575
diff changeset
70 errorCode_(errorCode),
1644
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
71 httpStatus_(ConvertErrorCodeToHttpStatus(errorCode))
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1575
diff changeset
72 {
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1575
diff changeset
73 }
1575
f8aae45011c9 exceptions now carry HTTP status
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
74
f8aae45011c9 exceptions now carry HTTP status
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
75 OrthancException(ErrorCode errorCode,
2960
74a5a7fd6e0e log flag to OrthancPluginSetHttpErrorDetails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2954
diff changeset
76 const std::string& details,
74a5a7fd6e0e log flag to OrthancPluginSetHttpErrorDetails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2954
diff changeset
77 bool log = true) :
2952
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
78 errorCode_(errorCode),
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
79 httpStatus_(ConvertErrorCodeToHttpStatus(errorCode)),
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
80 details_(new std::string(details))
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
81 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2952
diff changeset
82 #if ORTHANC_ENABLE_LOGGING == 1
2960
74a5a7fd6e0e log flag to OrthancPluginSetHttpErrorDetails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2954
diff changeset
83 if (log)
74a5a7fd6e0e log flag to OrthancPluginSetHttpErrorDetails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2954
diff changeset
84 {
74a5a7fd6e0e log flag to OrthancPluginSetHttpErrorDetails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2954
diff changeset
85 LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details;
74a5a7fd6e0e log flag to OrthancPluginSetHttpErrorDetails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2954
diff changeset
86 }
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2952
diff changeset
87 #endif
2952
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
88 }
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
89
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
90 OrthancException(ErrorCode errorCode,
1575
f8aae45011c9 exceptions now carry HTTP status
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
91 HttpStatus httpStatus) :
f8aae45011c9 exceptions now carry HTTP status
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
92 errorCode_(errorCode),
1644
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
93 httpStatus_(httpStatus)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
2952
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
97 OrthancException(ErrorCode errorCode,
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
98 HttpStatus httpStatus,
2960
74a5a7fd6e0e log flag to OrthancPluginSetHttpErrorDetails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2954
diff changeset
99 const std::string& details,
74a5a7fd6e0e log flag to OrthancPluginSetHttpErrorDetails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2954
diff changeset
100 bool log = true) :
2952
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
101 errorCode_(errorCode),
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
102 httpStatus_(httpStatus),
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
103 details_(new std::string(details))
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
104 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2952
diff changeset
105 #if ORTHANC_ENABLE_LOGGING == 1
2960
74a5a7fd6e0e log flag to OrthancPluginSetHttpErrorDetails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2954
diff changeset
106 if (log)
74a5a7fd6e0e log flag to OrthancPluginSetHttpErrorDetails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2954
diff changeset
107 {
74a5a7fd6e0e log flag to OrthancPluginSetHttpErrorDetails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2954
diff changeset
108 LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details;
74a5a7fd6e0e log flag to OrthancPluginSetHttpErrorDetails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2954
diff changeset
109 }
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2952
diff changeset
110 #endif
2952
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
111 }
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
112
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 ErrorCode GetErrorCode() const
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 {
1575
f8aae45011c9 exceptions now carry HTTP status
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
115 return errorCode_;
f8aae45011c9 exceptions now carry HTTP status
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
116 }
f8aae45011c9 exceptions now carry HTTP status
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
117
f8aae45011c9 exceptions now carry HTTP status
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
118 HttpStatus GetHttpStatus() const
f8aae45011c9 exceptions now carry HTTP status
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
119 {
f8aae45011c9 exceptions now carry HTTP status
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
120 return httpStatus_;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1575
diff changeset
123 const char* What() const
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1575
diff changeset
124 {
1583
9ea3d082b064 got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
125 return EnumerationToString(errorCode_);
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1575
diff changeset
126 }
2952
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
127
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
128 bool HasDetails() const
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
129 {
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
130 return details_.get() != NULL;
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
131 }
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
132
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
133 const char* GetDetails() const
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
134 {
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
135 if (details_.get() == NULL)
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
136 {
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
137 return "";
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
138 }
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
139 else
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
140 {
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
141 return details_->c_str();
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
142 }
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
143 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }