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)
CURLcode code{curl_easy_setopt(_connection, CURLOPT_ERRORBUFFER,
_curl_buffer_error)};
if (code != CURLE_OK)
{
throw CURLException{code, "Failed to set error buffer."};
}
curl_easy_setopt(_connection, CURLOPT_ERRORBUFFER, _curl_buffer_error);
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
code = curl_easy_setopt(_connection, CURLOPT_WRITEFUNCTION,
writer_body_wrapper);
if (code != CURLE_OK)
{
throw CURLException{code, "Failed to set write function",
_curl_buffer_error};
}
curl_easy_setopt(_connection, CURLOPT_WRITEFUNCTION, writer_body_wrapper);
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
curl_easy_setopt(_connection, CURLOPT_WRITEDATA, this);
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
code = curl_easy_setopt(_connection, CURLOPT_WRITEDATA, this);
if (code != CURLE_OK)
{
throw CURLException{code, "Failed to set write data",
_curl_buffer_error};
}
curl_easy_setopt(_connection, CURLOPT_HEADERFUNCTION,
writer_header_wrapper);
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
curl_easy_setopt(_connection, CURLOPT_HEADERDATA, this);
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
code = curl_easy_setopt(_connection, CURLOPT_HEADERFUNCTION,
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};
}
curl_easy_setopt(_connection, CURLOPT_XFERINFOFUNCTION, progress_wrapper);
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
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)
curl_easy_setopt(_connection, CURLOPT_NOPROGRESS, 0L);
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
code = curl_easy_setopt(_connection, CURLOPT_USERAGENT,
(string("mastorss/") += version).c_str());
CURLcode code{curl_easy_setopt(_connection, CURLOPT_USERAGENT,
(string("mastorss/") += version).c_str())};
if (code != CURLE_OK)
{
throw CURLException{code, "Failed to set User-Agent",