annotate OrthancFramework/Sources/OrthancException.cpp @ 5262:bf304ee8dd80

revert precompiled headers, as they really help
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Apr 2023 15:53:32 +0200
parents 0ea402b4d901
children 48b8dae6dc77
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
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5100
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5100
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * 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
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * Lesser General Public License for more details.
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * License along with this program. If not, see
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * <http://www.gnu.org/licenses/>.
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
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 #include "PrecompiledHeaders.h"
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "OrthancException.h"
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "Logging.h"
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
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 namespace Orthanc
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 OrthancException::OrthancException(const OrthancException& other) :
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 if (other.details_.get() != NULL)
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 details_.reset(new std::string(*other.details_));
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 }
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 OrthancException::OrthancException(ErrorCode errorCode) :
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
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 OrthancException::OrthancException(ErrorCode errorCode,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 const std::string& details,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 bool log) :
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 errorCode_(errorCode),
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 details_(new std::string(details))
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 #if ORTHANC_ENABLE_LOGGING == 1
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 if (log)
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details;
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 #endif
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
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 OrthancException::OrthancException(ErrorCode errorCode,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 HttpStatus httpStatus) :
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
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 OrthancException::OrthancException(ErrorCode errorCode,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 HttpStatus httpStatus,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 const std::string& details,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 bool log) :
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 errorCode_(errorCode),
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 details_(new std::string(details))
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 #if ORTHANC_ENABLE_LOGGING == 1
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 if (log)
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details;
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 #endif
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
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 ErrorCode OrthancException::GetErrorCode() const
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 return errorCode_;
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
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 HttpStatus OrthancException::GetHttpStatus() const
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 return httpStatus_;
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
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 const char* OrthancException::What() const
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 return EnumerationToString(errorCode_);
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
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 bool OrthancException::HasDetails() const
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 return details_.get() != NULL;
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
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 const char* OrthancException::GetDetails() const
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 if (details_.get() == NULL)
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 return "";
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 else
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 return details_->c_str();
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }