Mercurial > hg > orthanc
annotate OrthancFramework/Sources/OrthancException.cpp @ 5351:39fb52298083 Orthanc-1.11.3
closing branch Orthanc-1.11.3
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 04 Jul 2023 12:21:14 +0200 |
parents | 9d51c000e91a |
children | 0ea402b4d901 |
rev | line source |
---|---|
4304 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
4304 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU Lesser General Public License | |
10 * as published by the Free Software Foundation, either version 3 of | |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Lesser General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Lesser General Public | |
19 * License along with this program. If not, see | |
20 * <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
24 #include "PrecompiledHeaders.h" | |
25 #include "OrthancException.h" | |
26 | |
27 #include "Logging.h" | |
28 | |
29 | |
30 namespace Orthanc | |
31 { | |
32 OrthancException::OrthancException(const OrthancException& other) : | |
33 errorCode_(other.errorCode_), | |
5100
9d51c000e91a
more verbose HTTPClient errors + avoid duplicate logging of same error
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
34 httpStatus_(other.httpStatus_), |
9d51c000e91a
more verbose HTTPClient errors + avoid duplicate logging of same error
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
35 logged_(false) |
4304 | 36 { |
37 if (other.details_.get() != NULL) | |
38 { | |
39 details_.reset(new std::string(*other.details_)); | |
40 } | |
41 } | |
42 | |
43 OrthancException::OrthancException(ErrorCode errorCode) : | |
44 errorCode_(errorCode), | |
5100
9d51c000e91a
more verbose HTTPClient errors + avoid duplicate logging of same error
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
45 httpStatus_(ConvertErrorCodeToHttpStatus(errorCode)), |
9d51c000e91a
more verbose HTTPClient errors + avoid duplicate logging of same error
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
46 logged_(false) |
4304 | 47 { |
48 } | |
49 | |
50 OrthancException::OrthancException(ErrorCode errorCode, | |
51 const std::string& details, | |
52 bool log) : | |
53 errorCode_(errorCode), | |
54 httpStatus_(ConvertErrorCodeToHttpStatus(errorCode)), | |
5100
9d51c000e91a
more verbose HTTPClient errors + avoid duplicate logging of same error
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
55 logged_(log), |
4304 | 56 details_(new std::string(details)) |
57 { | |
58 #if ORTHANC_ENABLE_LOGGING == 1 | |
59 if (log) | |
60 { | |
61 LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details; | |
62 } | |
63 #endif | |
64 } | |
65 | |
66 OrthancException::OrthancException(ErrorCode errorCode, | |
67 HttpStatus httpStatus) : | |
68 errorCode_(errorCode), | |
5100
9d51c000e91a
more verbose HTTPClient errors + avoid duplicate logging of same error
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
69 httpStatus_(httpStatus), |
9d51c000e91a
more verbose HTTPClient errors + avoid duplicate logging of same error
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
70 logged_(false) |
4304 | 71 { |
72 } | |
73 | |
74 OrthancException::OrthancException(ErrorCode errorCode, | |
75 HttpStatus httpStatus, | |
76 const std::string& details, | |
77 bool log) : | |
78 errorCode_(errorCode), | |
79 httpStatus_(httpStatus), | |
5100
9d51c000e91a
more verbose HTTPClient errors + avoid duplicate logging of same error
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
80 logged_(log), |
4304 | 81 details_(new std::string(details)) |
82 { | |
83 #if ORTHANC_ENABLE_LOGGING == 1 | |
84 if (log) | |
85 { | |
86 LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details; | |
87 } | |
88 #endif | |
89 } | |
90 | |
91 ErrorCode OrthancException::GetErrorCode() const | |
92 { | |
93 return errorCode_; | |
94 } | |
95 | |
96 HttpStatus OrthancException::GetHttpStatus() const | |
97 { | |
98 return httpStatus_; | |
99 } | |
100 | |
101 const char* OrthancException::What() const | |
102 { | |
103 return EnumerationToString(errorCode_); | |
104 } | |
105 | |
106 bool OrthancException::HasDetails() const | |
107 { | |
108 return details_.get() != NULL; | |
109 } | |
110 | |
111 const char* OrthancException::GetDetails() const | |
112 { | |
113 if (details_.get() == NULL) | |
114 { | |
115 return ""; | |
116 } | |
117 else | |
118 { | |
119 return details_->c_str(); | |
120 } | |
121 } | |
5100
9d51c000e91a
more verbose HTTPClient errors + avoid duplicate logging of same error
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
122 |
9d51c000e91a
more verbose HTTPClient errors + avoid duplicate logging of same error
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
123 bool OrthancException::HasBeenLogged() const |
9d51c000e91a
more verbose HTTPClient errors + avoid duplicate logging of same error
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
124 { |
9d51c000e91a
more verbose HTTPClient errors + avoid duplicate logging of same error
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
125 return logged_; |
9d51c000e91a
more verbose HTTPClient errors + avoid duplicate logging of same error
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
126 } |
9d51c000e91a
more verbose HTTPClient errors + avoid duplicate logging of same error
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
127 |
4304 | 128 } |