diff --git a/es-core/src/HttpReq.cpp b/es-core/src/HttpReq.cpp index bd82b7263..9b6fb043e 100644 --- a/es-core/src/HttpReq.cpp +++ b/es-core/src/HttpReq.cpp @@ -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));