Only check for libcurl return code if it could return an error.

This commit is contained in:
tastytea 2020-01-08 21:34:57 +01:00
parent d2de78ff9e
commit 0e3b812b54
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 11 additions and 52 deletions

View File

@ -203,70 +203,29 @@ void CURLWrapper::setup_curl()
} }
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
CURLcode code{curl_easy_setopt(_connection, CURLOPT_ERRORBUFFER, curl_easy_setopt(_connection, CURLOPT_ERRORBUFFER, _curl_buffer_error);
_curl_buffer_error)};
if (code != CURLE_OK)
{
throw CURLException{code, "Failed to set error buffer."};
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
code = curl_easy_setopt(_connection, CURLOPT_WRITEFUNCTION, curl_easy_setopt(_connection, CURLOPT_WRITEFUNCTION, writer_body_wrapper);
writer_body_wrapper); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
if (code != CURLE_OK) curl_easy_setopt(_connection, CURLOPT_WRITEDATA, this);
{
throw CURLException{code, "Failed to set write function",
_curl_buffer_error};
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
code = curl_easy_setopt(_connection, CURLOPT_WRITEDATA, this); curl_easy_setopt(_connection, CURLOPT_HEADERFUNCTION,
if (code != CURLE_OK) writer_header_wrapper);
{ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
throw CURLException{code, "Failed to set write data", curl_easy_setopt(_connection, CURLOPT_HEADERDATA, this);
_curl_buffer_error};
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
code = curl_easy_setopt(_connection, CURLOPT_HEADERFUNCTION, curl_easy_setopt(_connection, CURLOPT_XFERINFOFUNCTION, progress_wrapper);
writer_header_wrapper);
if (code != CURLE_OK)
{
throw CURLException{code, "Failed to set header function",
_curl_buffer_error};
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
code = curl_easy_setopt(_connection, CURLOPT_HEADERDATA, this);
if (code != CURLE_OK)
{
throw CURLException{code, "Failed to set header data",
_curl_buffer_error};
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
code = curl_easy_setopt(_connection, CURLOPT_XFERINFOFUNCTION,
progress_wrapper);
if (code != CURLE_OK)
{
throw CURLException{code, "Failed to set transfer info function",
_curl_buffer_error};
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
curl_easy_setopt(_connection, CURLOPT_XFERINFODATA, this); curl_easy_setopt(_connection, CURLOPT_XFERINFODATA, this);
if (code != CURLE_OK)
{
throw CURLException{code, "Failed to set transfer info data",
_curl_buffer_error};
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
curl_easy_setopt(_connection, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(_connection, CURLOPT_NOPROGRESS, 0L);
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
code = curl_easy_setopt(_connection, CURLOPT_USERAGENT, CURLcode code{curl_easy_setopt(_connection, CURLOPT_USERAGENT,
(string("mastorss/") += version).c_str()); (string("mastorss/") += version).c_str())};
if (code != CURLE_OK) if (code != CURLE_OK)
{ {
throw CURLException{code, "Failed to set User-Agent", throw CURLException{code, "Failed to set User-Agent",