1 /** 2 * Orthanc - A Lightweight, RESTful DICOM Store 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics 4 * Department, University Hospital of Liege, Belgium 5 * Copyright (C) 2017-2020 Osimis S.A., Belgium 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 { OrthancException(const OrthancException & other)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 OrthancException(ErrorCode errorCode)41 OrthancException::OrthancException(ErrorCode errorCode) : 42 errorCode_(errorCode), 43 httpStatus_(ConvertErrorCodeToHttpStatus(errorCode)) 44 { 45 } 46 OrthancException(ErrorCode errorCode,const std::string & details,bool log)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 OrthancException(ErrorCode errorCode,HttpStatus httpStatus)62 OrthancException::OrthancException(ErrorCode errorCode, 63 HttpStatus httpStatus) : 64 errorCode_(errorCode), 65 httpStatus_(httpStatus) 66 { 67 } 68 OrthancException(ErrorCode errorCode,HttpStatus httpStatus,const std::string & details,bool log)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 GetErrorCode() const85 ErrorCode OrthancException::GetErrorCode() const 86 { 87 return errorCode_; 88 } 89 GetHttpStatus() const90 HttpStatus OrthancException::GetHttpStatus() const 91 { 92 return httpStatus_; 93 } 94 What() const95 const char* OrthancException::What() const 96 { 97 return EnumerationToString(errorCode_); 98 } 99 HasDetails() const100 bool OrthancException::HasDetails() const 101 { 102 return details_.get() != NULL; 103 } 104 GetDetails() const105 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 } 117