Mercurial > hg > orthanc
diff 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 |
line wrap: on
line diff
--- a/OrthancFramework/Sources/HttpClient.cpp Wed Oct 19 08:57:34 2022 +0200 +++ b/OrthancFramework/Sources/HttpClient.cpp Wed Oct 19 12:40:14 2022 +0200 @@ -55,9 +55,6 @@ } else { - LOG(ERROR) << "Error code " << static_cast<int>(code) - << " in libcurl: " << curl_easy_strerror(code) - << " while accessing url: " << url; *status = 0; return code; } @@ -102,6 +99,24 @@ return code; } + static CURLcode CheckCode(CURLcode code, const std::string& url) + { + if (code == CURLE_NOT_BUILT_IN) + { + throw OrthancException(ErrorCode_InternalError, + "Your libcurl does not contain a required feature, " + "please recompile Orthanc with -DUSE_SYSTEM_CURL=OFF"); + } + + if (code != CURLE_OK) + { + throw OrthancException(ErrorCode_NetworkProtocol, + "libCURL error: " + std::string(curl_easy_strerror(code)) + " while accessing " + url); + } + + return code; + } + // RAII pattern around a "curl_slist" class HttpClient::CurlHeaders : public boost::noncopyable @@ -1064,7 +1079,7 @@ CLOG(INFO, HTTP) << "cURL status code: " << code; } - CheckCode(code); + CheckCode(code, url_); // throws on HTTP error if (status == 0) {