mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-30 03:15:38 -05:00
Merge pull request #321 from FireMario211/patch-1
Handle HTTP error responses
This commit is contained in:
commit
b708d1ecf6
1 changed files with 8 additions and 3 deletions
|
@ -271,7 +271,7 @@ SentAsyncWebRequest::Impl::Impl(SentAsyncWebRequest* self, AsyncWebRequest const
|
||||||
// Follow redirects
|
// Follow redirects
|
||||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
|
||||||
// Fail if response code is 4XX or 5XX
|
// Fail if response code is 4XX or 5XX
|
||||||
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
|
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 0L); // we will handle http errors manually
|
||||||
|
|
||||||
// Headers end
|
// Headers end
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||||
|
@ -307,12 +307,17 @@ SentAsyncWebRequest::Impl::Impl(SentAsyncWebRequest* self, AsyncWebRequest const
|
||||||
);
|
);
|
||||||
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &data);
|
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &data);
|
||||||
auto res = curl_easy_perform(curl);
|
auto res = curl_easy_perform(curl);
|
||||||
if (res != CURLE_OK) {
|
|
||||||
long code = 0;
|
long code = 0;
|
||||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
return this->error("Fetch failed: " + std::string(curl_easy_strerror(res)), code);
|
return this->error("Fetch failed: " + std::string(curl_easy_strerror(res)), code);
|
||||||
}
|
}
|
||||||
|
if (code >= 400 && code < 600) {
|
||||||
|
std::string response_str(ret.begin(), ret.end());
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
return this->error(response_str, code);
|
||||||
|
}
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
|
|
||||||
AWAIT_RESUME();
|
AWAIT_RESUME();
|
||||||
|
|
Loading…
Reference in a new issue