UI: Add fail_on_error parameter to GetRemoteFile

CURLOPT_FAILONERROR swallows the body of 40X responses,
but in some cases we want to read the body for error details.
master
derrod 2021-08-16 02:44:53 +02:00 committed by Rodney
parent dd6dd4e104
commit 64b21ad12f
2 changed files with 5 additions and 3 deletions

View File

@ -123,7 +123,7 @@ bool GetRemoteFile(const char *url, std::string &str, std::string &error,
long *responseCode, const char *contentType,
std::string request_type, const char *postData,
std::vector<std::string> extraHeaders,
std::string *signature, int timeoutSec)
std::string *signature, int timeoutSec, bool fail_on_error)
{
vector<string> header_in_list;
char error_in[CURL_ERROR_SIZE];
@ -158,7 +158,8 @@ bool GetRemoteFile(const char *url, std::string &str, std::string &error,
curl_easy_setopt(curl.get(), CURLOPT_ACCEPT_ENCODING, "");
curl_easy_setopt(curl.get(), CURLOPT_HTTPHEADER, header);
curl_easy_setopt(curl.get(), CURLOPT_ERRORBUFFER, error_in);
curl_easy_setopt(curl.get(), CURLOPT_FAILONERROR, 1L);
if (fail_on_error)
curl_easy_setopt(curl.get(), CURLOPT_FAILONERROR, 1L);
curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION,
string_write);
curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, &str);

View File

@ -68,4 +68,5 @@ bool GetRemoteFile(
long *responseCode = nullptr, const char *contentType = nullptr,
std::string request_type = "", const char *postData = nullptr,
std::vector<std::string> extraHeaders = std::vector<std::string>(),
std::string *signature = nullptr, int timeoutSec = 0);
std::string *signature = nullptr, int timeoutSec = 0,
bool fail_on_error = true);