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