annotate OrthancFramework/Sources/OrthancException.cpp @ 5013:c074a5827da9

todo
author Alain Mazy <am@osimis.io>
date Wed, 08 Jun 2022 15:46:24 +0200
parents 43e613a7756b
children 9d51c000e91a
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
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
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_),
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 httpStatus_(other.httpStatus_)
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 if (other.details_.get() != NULL)
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 details_.reset(new std::string(*other.details_));
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 }
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 OrthancException::OrthancException(ErrorCode errorCode) :
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 errorCode_(errorCode),
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 httpStatus_(ConvertErrorCodeToHttpStatus(errorCode))
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 }
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 OrthancException::OrthancException(ErrorCode errorCode,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 const std::string& details,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 bool log) :
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 errorCode_(errorCode),
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 httpStatus_(ConvertErrorCodeToHttpStatus(errorCode)),
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 details_(new std::string(details))
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 #if ORTHANC_ENABLE_LOGGING == 1
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 if (log)
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 LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details;
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 #endif
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
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 OrthancException::OrthancException(ErrorCode errorCode,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 HttpStatus httpStatus) :
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 errorCode_(errorCode),
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 httpStatus_(httpStatus)
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 OrthancException::OrthancException(ErrorCode errorCode,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 HttpStatus httpStatus,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 const std::string& details,
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 bool log) :
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 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 details_(new std::string(details))
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 #if ORTHANC_ENABLE_LOGGING == 1
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 if (log)
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 LOG(ERROR) << EnumerationToString(errorCode_) << ": " << 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 #endif
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
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 ErrorCode OrthancException::GetErrorCode() const
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 return errorCode_;
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 HttpStatus OrthancException::GetHttpStatus() 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 httpStatus_;
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 const char* OrthancException::What() 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 EnumerationToString(errorCode_);
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 bool OrthancException::HasDetails() 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 details_.get() != NULL;
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 const char* OrthancException::GetDetails() 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 if (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 return "";
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 else
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 return details_->c_str();
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 }
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }