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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * modify it under the terms of the GNU Lesser General Public License
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * as published by the Free Software Foundation, either version 3 of
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * the License, or (at your option) any later version.
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * Lesser General Public License for more details.
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * License along with this program. If not, see
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * <http://www.gnu.org/licenses/>.
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 **/
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "PrecompiledHeaders.h"
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "OrthancException.h"
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "Logging.h"
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 namespace Orthanc
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 OrthancException::OrthancException(const OrthancException& other) :
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 if (other.details_.get() != NULL)
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 details_.reset(new std::string(*other.details_));
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 OrthancException::OrthancException(ErrorCode errorCode) :
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 OrthancException::OrthancException(ErrorCode errorCode,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 const std::string& details,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 bool log) :
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 errorCode_(errorCode),
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 details_(new std::string(details))
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 #if ORTHANC_ENABLE_LOGGING == 1
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 if (log)
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details;
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 #endif
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 OrthancException::OrthancException(ErrorCode errorCode,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 HttpStatus httpStatus) :
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 OrthancException::OrthancException(ErrorCode errorCode,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 HttpStatus httpStatus,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 const std::string& details,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 bool log) :
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 errorCode_(errorCode),
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 details_(new std::string(details))
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 #if ORTHANC_ENABLE_LOGGING == 1
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 if (log)
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details;
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 #endif
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 ErrorCode OrthancException::GetErrorCode() const
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 return errorCode_;
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 HttpStatus OrthancException::GetHttpStatus() const
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 return httpStatus_;
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 const char* OrthancException::What() const
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 return EnumerationToString(errorCode_);
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 bool OrthancException::HasDetails() const
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 return details_.get() != NULL;
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 const char* OrthancException::GetDetails() const
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 if (details_.get() == NULL)
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 return "";
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 else
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 return details_->c_str();
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }