Common: Fix logger related crash when HTTP response is empty

This commit is contained in:
Thomas May 2020-10-27 11:05:53 +00:00 committed by Léo Lam
parent fe727ed1d0
commit 72e1131123
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
1 changed files with 10 additions and 2 deletions

View File

@ -220,9 +220,17 @@ HttpRequest::Response HttpRequest::Impl::Fetch(const std::string& url, Method me
long response_code = 0; long response_code = 0;
curl_easy_getinfo(m_curl.get(), CURLINFO_RESPONSE_CODE, &response_code); curl_easy_getinfo(m_curl.get(), CURLINFO_RESPONSE_CODE, &response_code);
if (response_code != 200) if (response_code != 200)
{
if (buffer.empty())
{
ERROR_LOG_FMT(COMMON, "Failed to {} {}: server replied with code {}", type, url,
response_code);
}
else
{ {
ERROR_LOG_FMT(COMMON, "Failed to {} {}: server replied with code {} and body\n\x1b[0m{:.{}}", ERROR_LOG_FMT(COMMON, "Failed to {} {}: server replied with code {} and body\n\x1b[0m{:.{}}",
type, url, response_code, buffer.data(), static_cast<int>(buffer.size())); type, url, response_code, buffer.data(), static_cast<int>(buffer.size()));
}
return {}; return {};
} }