diff --git a/src/common/http_downloader.cpp b/src/common/http_downloader.cpp index 9180b20b1..e0f898a9a 100644 --- a/src/common/http_downloader.cpp +++ b/src/common/http_downloader.cpp @@ -110,7 +110,7 @@ void HTTPDownloader::LockedPollRequests(std::unique_lock& lock) m_pending_http_requests.erase(m_pending_http_requests.begin() + index); lock.unlock(); - req->callback(-1, std::string(), Request::Data()); + req->callback(HTTP_STATUS_TIMEOUT, std::string(), Request::Data()); CloseRequest(req); diff --git a/src/common/http_downloader.h b/src/common/http_downloader.h index 8da450cc3..f9eb01f10 100644 --- a/src/common/http_downloader.h +++ b/src/common/http_downloader.h @@ -18,7 +18,10 @@ class HTTPDownloader public: enum : s32 { - HTTP_OK = 200 + HTTP_STATUS_CANCELLED = -3, + HTTP_STATUS_TIMEOUT = -2, + HTTP_STATUS_ERROR = -1, + HTTP_STATUS_OK = 200 }; struct Request diff --git a/src/common/http_downloader_winhttp.cpp b/src/common/http_downloader_winhttp.cpp index 18d381bec..3af53abab 100644 --- a/src/common/http_downloader_winhttp.cpp +++ b/src/common/http_downloader_winhttp.cpp @@ -90,7 +90,7 @@ void CALLBACK HTTPDownloaderWinHttp::HTTPStatusCallback(HINTERNET hRequest, DWOR { const WINHTTP_ASYNC_RESULT* res = reinterpret_cast(lpvStatusInformation); Log_ErrorPrintf("WinHttp async function %p returned error %u", res->dwResult, res->dwError); - req->status_code = -1; + req->status_code = HTTP_STATUS_ERROR; req->state.store(Request::State::Complete); return; } @@ -100,7 +100,7 @@ void CALLBACK HTTPDownloaderWinHttp::HTTPStatusCallback(HINTERNET hRequest, DWOR if (!WinHttpReceiveResponse(hRequest, nullptr)) { Log_ErrorPrintf("WinHttpReceiveResponse() failed: %u", GetLastError()); - req->status_code = -1; + req->status_code = HTTP_STATUS_ERROR; req->state.store(Request::State::Complete); } @@ -115,7 +115,7 @@ void CALLBACK HTTPDownloaderWinHttp::HTTPStatusCallback(HINTERNET hRequest, DWOR WINHTTP_HEADER_NAME_BY_INDEX, &req->status_code, &buffer_size, WINHTTP_NO_HEADER_INDEX)) { Log_ErrorPrintf("WinHttpQueryHeaders() for status code failed: %u", GetLastError()); - req->status_code = -1; + req->status_code = HTTP_STATUS_ERROR; req->state.store(Request::State::Complete); return; } @@ -153,7 +153,7 @@ void CALLBACK HTTPDownloaderWinHttp::HTTPStatusCallback(HINTERNET hRequest, DWOR if (!WinHttpQueryDataAvailable(hRequest, nullptr) && GetLastError() != ERROR_IO_PENDING) { Log_ErrorPrintf("WinHttpQueryDataAvailable() failed: %u", GetLastError()); - req->status_code = -1; + req->status_code = HTTP_STATUS_ERROR; req->state.store(Request::State::Complete); } @@ -179,7 +179,7 @@ void CALLBACK HTTPDownloaderWinHttp::HTTPStatusCallback(HINTERNET hRequest, DWOR GetLastError() != ERROR_IO_PENDING) { Log_ErrorPrintf("WinHttpReadData() failed: %u", GetLastError()); - req->status_code = -1; + req->status_code = HTTP_STATUS_ERROR; req->state.store(Request::State::Complete); } @@ -197,7 +197,7 @@ void CALLBACK HTTPDownloaderWinHttp::HTTPStatusCallback(HINTERNET hRequest, DWOR if (!WinHttpQueryDataAvailable(hRequest, nullptr) && GetLastError() != ERROR_IO_PENDING) { Log_ErrorPrintf("WinHttpQueryDataAvailable() failed: %u", GetLastError()); - req->status_code = -1; + req->status_code = HTTP_STATUS_ERROR; req->state.store(Request::State::Complete); } @@ -239,7 +239,7 @@ bool HTTPDownloaderWinHttp::StartRequest(HTTPDownloader::Request* request) if (!WinHttpCrackUrl(url_wide.c_str(), static_cast(url_wide.size()), 0, &uc)) { Log_ErrorPrintf("WinHttpCrackUrl() failed: %u", GetLastError()); - req->callback(-1, std::string(), req->data); + req->callback(HTTP_STATUS_ERROR, std::string(), req->data); delete req; return false; } @@ -251,7 +251,7 @@ bool HTTPDownloaderWinHttp::StartRequest(HTTPDownloader::Request* request) if (!req->hConnection) { Log_ErrorPrintf("Failed to start HTTP request for '%s': %u", req->url.c_str(), GetLastError()); - req->callback(-1, std::string(), req->data); + req->callback(HTTP_STATUS_ERROR, std::string(), req->data); delete req; return false; } @@ -284,7 +284,7 @@ bool HTTPDownloaderWinHttp::StartRequest(HTTPDownloader::Request* request) if (!result && GetLastError() != ERROR_IO_PENDING) { Log_ErrorPrintf("WinHttpSendRequest() failed: %u", GetLastError()); - req->status_code = -1; + req->status_code = HTTP_STATUS_ERROR; req->state.store(Request::State::Complete); } diff --git a/src/core/achievements.cpp b/src/core/achievements.cpp index e31e41d81..ffd12d019 100644 --- a/src/core/achievements.cpp +++ b/src/core/achievements.cpp @@ -307,7 +307,7 @@ void Achievements::DownloadImage(std::string url, std::string cache_filename) { auto callback = [cache_filename](s32 status_code, std::string content_type, Common::HTTPDownloader::Request::Data data) { - if (status_code != Common::HTTPDownloader::HTTP_OK) + if (status_code != Common::HTTPDownloader::HTTP_STATUS_OK) return; if (!FileSystem::WriteBinaryFile(cache_filename.c_str(), data.data(), data.size())) @@ -616,7 +616,10 @@ void Achievements::ClientServerCall(const rc_api_request_t* request, rc_client_s Common::HTTPDownloader::Request::Callback hd_callback = [callback, callback_data](s32 status_code, std::string content_type, Common::HTTPDownloader::Request::Data data) { rc_api_server_response_t rr; - rr.http_status_code = status_code; + rr.http_status_code = (status_code <= 0) ? (status_code == Common::HTTPDownloader::HTTP_STATUS_CANCELLED ? + RC_API_SERVER_RESPONSE_CLIENT_ERROR : + RC_API_SERVER_RESPONSE_RETRYABLE_CLIENT_ERROR) : + status_code; rr.body_length = data.size(); rr.body = reinterpret_cast(data.data()); diff --git a/src/core/game_list.cpp b/src/core/game_list.cpp index 2e279d631..7c8c69ce4 100644 --- a/src/core/game_list.cpp +++ b/src/core/game_list.cpp @@ -1169,7 +1169,7 @@ bool GameList::DownloadCovers(const std::vector& url_templates, boo downloader->CreateRequest( std::move(url), [use_serial, &save_callback, entry_path = std::move(entry_path), filename = std::move(filename)]( s32 status_code, std::string content_type, Common::HTTPDownloader::Request::Data data) { - if (status_code != Common::HTTPDownloader::HTTP_OK || data.empty()) + if (status_code != Common::HTTPDownloader::HTTP_STATUS_OK || data.empty()) return; std::unique_lock lock(s_mutex);