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