From a595930fcfa54b017e144e13f552e0a92b3b58ec Mon Sep 17 00:00:00 2001 From: algolia-bot Date: Tue, 19 Nov 2024 10:58:25 +0000 Subject: [PATCH] fix(cts): add tests for HTML error (generated) https://github.com/algolia/api-clients-automation/pull/4097 Co-authored-by: algolia-bot Co-authored-by: Pierre Millot --- lib/Http/CurlHttpClient.php | 3 ++- lib/RetryStrategy/ApiWrapper.php | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Http/CurlHttpClient.php b/lib/Http/CurlHttpClient.php index b1f11d38..add7b1bf 100644 --- a/lib/Http/CurlHttpClient.php +++ b/lib/Http/CurlHttpClient.php @@ -116,11 +116,12 @@ public function sendRequest( $statusCode = (int) curl_getinfo($curlHandle, CURLINFO_HTTP_CODE); $responseBody = curl_multi_getcontent($curlHandle); $error = curl_error($curlHandle); + $contentType = curl_getinfo($curlHandle, CURLINFO_CONTENT_TYPE); $this->releaseMHandle($curlHandle); curl_close($curlHandle); - return new Response($statusCode, [], $responseBody, '1.1', $error); + return new Response($statusCode, ['Content-Type' => $contentType], $responseBody, '1.1', $error); } private function getMHandle($curlHandle) diff --git a/lib/RetryStrategy/ApiWrapper.php b/lib/RetryStrategy/ApiWrapper.php index d194b02e..4f9bb184 100644 --- a/lib/RetryStrategy/ApiWrapper.php +++ b/lib/RetryStrategy/ApiWrapper.php @@ -247,6 +247,11 @@ private function handleResponse( throw new RetriableException('Retriable failure on '.$request->getUri()->getHost().': '.$reason, $statusCode); } + // handle HTML error responses + if (false !== strpos($response->getHeaderLine('Content-Type'), 'text/html')) { + throw new AlgoliaException($statusCode.': '.$response->getReasonPhrase(), $statusCode); + } + $responseArray = Helpers::json_decode($body, true); if (404 === $statusCode) {