Mercurial > hg > orthanc
comparison OrthancFramework/Sources/HttpClient.cpp @ 5100:9d51c000e91a
more verbose HTTPClient errors + avoid duplicate logging of same error
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 19 Oct 2022 12:40:14 +0200 |
parents | b52fe770aec0 |
children | 95d8e0540219 |
comparison
equal
deleted
inserted
replaced
5099:edefb278cb77 | 5100:9d51c000e91a |
---|---|
53 code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, status); | 53 code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, status); |
54 return code; | 54 return code; |
55 } | 55 } |
56 else | 56 else |
57 { | 57 { |
58 LOG(ERROR) << "Error code " << static_cast<int>(code) | |
59 << " in libcurl: " << curl_easy_strerror(code) | |
60 << " while accessing url: " << url; | |
61 *status = 0; | 58 *status = 0; |
62 return code; | 59 return code; |
63 } | 60 } |
64 } | 61 } |
65 } | 62 } |
100 } | 97 } |
101 | 98 |
102 return code; | 99 return code; |
103 } | 100 } |
104 | 101 |
102 static CURLcode CheckCode(CURLcode code, const std::string& url) | |
103 { | |
104 if (code == CURLE_NOT_BUILT_IN) | |
105 { | |
106 throw OrthancException(ErrorCode_InternalError, | |
107 "Your libcurl does not contain a required feature, " | |
108 "please recompile Orthanc with -DUSE_SYSTEM_CURL=OFF"); | |
109 } | |
110 | |
111 if (code != CURLE_OK) | |
112 { | |
113 throw OrthancException(ErrorCode_NetworkProtocol, | |
114 "libCURL error: " + std::string(curl_easy_strerror(code)) + " while accessing " + url); | |
115 } | |
116 | |
117 return code; | |
118 } | |
119 | |
105 | 120 |
106 // RAII pattern around a "curl_slist" | 121 // RAII pattern around a "curl_slist" |
107 class HttpClient::CurlHeaders : public boost::noncopyable | 122 class HttpClient::CurlHeaders : public boost::noncopyable |
108 { | 123 { |
109 private: | 124 private: |
1062 if (isVerbose_) | 1077 if (isVerbose_) |
1063 { | 1078 { |
1064 CLOG(INFO, HTTP) << "cURL status code: " << code; | 1079 CLOG(INFO, HTTP) << "cURL status code: " << code; |
1065 } | 1080 } |
1066 | 1081 |
1067 CheckCode(code); | 1082 CheckCode(code, url_); // throws on HTTP error |
1068 | 1083 |
1069 if (status == 0) | 1084 if (status == 0) |
1070 { | 1085 { |
1071 // This corresponds to a call to an inexistent host | 1086 // This corresponds to a call to an inexistent host |
1072 lastStatus_ = HttpStatus_500_InternalServerError; | 1087 lastStatus_ = HttpStatus_500_InternalServerError; |