Skip to content

Commit

Permalink
fix(cts): add tests for HTML error (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#4097

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
  • Loading branch information
algolia-bot and millotp committed Nov 19, 2024
1 parent 0555dac commit a595930
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Http/CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions lib/RetryStrategy/ApiWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a595930

Please sign in to comment.