From 64b21ad12f39b46a2587f887d587fc547666167d Mon Sep 17 00:00:00 2001 From: derrod Date: Mon, 16 Aug 2021 02:44:53 +0200 Subject: [PATCH] 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. --- UI/remote-text.cpp | 5 +++-- UI/remote-text.hpp | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/UI/remote-text.cpp b/UI/remote-text.cpp index 9581ad460..50ed4f43c 100644 --- a/UI/remote-text.cpp +++ b/UI/remote-text.cpp @@ -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 extraHeaders, - std::string *signature, int timeoutSec) + std::string *signature, int timeoutSec, bool fail_on_error) { vector 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); diff --git a/UI/remote-text.hpp b/UI/remote-text.hpp index bc864c976..becb9a5f8 100644 --- a/UI/remote-text.hpp +++ b/UI/remote-text.hpp @@ -68,4 +68,5 @@ bool GetRemoteFile( long *responseCode = nullptr, const char *contentType = nullptr, std::string request_type = "", const char *postData = nullptr, std::vector extraHeaders = std::vector(), - std::string *signature = nullptr, int timeoutSec = 0); + std::string *signature = nullptr, int timeoutSec = 0, + bool fail_on_error = true);