Check http response code

This commit is contained in:
fed 2022-12-22 13:38:35 +01:00
parent fde0f341dd
commit 0fc70945a6
3 changed files with 13 additions and 1 deletions

View File

@ -174,7 +174,15 @@ namespace download
const auto& result = data.value();
if (result.code != CURLE_OK)
{
menu_error(utils::string::va("Download failed: %s (%i)\n", curl_easy_strerror(result.code), result.code));
menu_error(utils::string::va("Download failed: %s (%i)\n",
curl_easy_strerror(result.code), result.code));
return;
}
if (result.response_code >= 400)
{
menu_error(utils::string::va("Download failed: Server returned bad response code %i\n",
result.response_code));
return;
}

View File

@ -83,11 +83,14 @@ namespace utils::http
}
const auto code = curl_easy_perform(curl);
unsigned int response_code{};
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
if (code == CURLE_OK)
{
result result;
result.code = code;
result.response_code = response_code;
result.buffer = std::move(buffer);
return result;

View File

@ -12,6 +12,7 @@ namespace utils::http
struct result
{
CURLcode code{};
unsigned int response_code{};
std::string buffer{};
};