Skip to content

Commit a595930

Browse files
algolia-botmillotp
andcommitted
fix(cts): add tests for HTML error (generated)
algolia/api-clients-automation#4097 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent 0555dac commit a595930

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/Http/CurlHttpClient.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,12 @@ public function sendRequest(
116116
$statusCode = (int) curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
117117
$responseBody = curl_multi_getcontent($curlHandle);
118118
$error = curl_error($curlHandle);
119+
$contentType = curl_getinfo($curlHandle, CURLINFO_CONTENT_TYPE);
119120

120121
$this->releaseMHandle($curlHandle);
121122
curl_close($curlHandle);
122123

123-
return new Response($statusCode, [], $responseBody, '1.1', $error);
124+
return new Response($statusCode, ['Content-Type' => $contentType], $responseBody, '1.1', $error);
124125
}
125126

126127
private function getMHandle($curlHandle)

lib/RetryStrategy/ApiWrapper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ private function handleResponse(
247247
throw new RetriableException('Retriable failure on '.$request->getUri()->getHost().': '.$reason, $statusCode);
248248
}
249249

250+
// handle HTML error responses
251+
if (false !== strpos($response->getHeaderLine('Content-Type'), 'text/html')) {
252+
throw new AlgoliaException($statusCode.': '.$response->getReasonPhrase(), $statusCode);
253+
}
254+
250255
$responseArray = Helpers::json_decode($body, true);
251256

252257
if (404 === $statusCode) {

0 commit comments

Comments
 (0)