The HTTP error code will now be shown on scraper errors instead of the 'File is smaller than 350 bytes' message

This commit is contained in:
Leon Styhre 2023-12-24 11:48:14 +01:00
parent 0d845ba4af
commit cfb71c378f

View file

@ -194,6 +194,14 @@ HttpReq::HttpReq(const std::string& url, bool scraperRequest)
return;
}
// Fail on HTTP status codes >= 400.
err = curl_easy_setopt(mHandle, CURLOPT_FAILONERROR, 1L);
if (err != CURLE_OK) {
mStatus = REQ_IO_ERROR;
onError(curl_easy_strerror(err));
return;
}
// Add the handle to our multi.
CURLMcode merr {curl_multi_add_handle(sMultiHandle, mHandle)};
if (merr != CURLM_OK) {
@ -250,6 +258,12 @@ HttpReq::Status HttpReq::status()
req->mStatus = REQ_FAILED_VERIFICATION;
req->onError(curl_easy_strerror(msg->data.result));
}
else if (msg->data.result == CURLE_HTTP_RETURNED_ERROR) {
req->mStatus = REQ_BAD_STATUS_CODE;
long responseCode;
curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &responseCode);
req->onError("Server returned HTTP error code " + std::to_string(responseCode));
}
else {
req->mStatus = REQ_IO_ERROR;
req->onError(curl_easy_strerror(msg->data.result));