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