Skip to content

Commit 591455c

Browse files
committed
fix(api): throw on first case of 400s
- remove duplicate `$statusCode` variable assignment in `ApiCall.php` - clean up redundant conditional check for status code 408 - simplify exception handling flow for better code readability
1 parent 10f7229 commit 591455c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/ApiCall.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,20 @@ private function makeRequest(string $method, string $endPoint, bool $asJson, arr
266266
->getContents(), true, 512, JSON_THROW_ON_ERROR) : $response->getBody()
267267
->getContents();
268268
} catch (HttpException $exception) {
269-
if (
270-
$exception->getResponse()
271-
->getStatusCode() === 408
272-
) {
269+
$statusCode = $exception->getResponse()->getStatusCode();
270+
271+
if ($statusCode === 408) {
273272
continue;
274273
}
274+
275+
if (400 <= $statusCode && $statusCode < 500) {
276+
$this->setNodeHealthCheck($node, false);
277+
throw $this->getException($statusCode)
278+
->setMessage($exception->getMessage());
279+
}
280+
275281
$this->setNodeHealthCheck($node, false);
276-
$lastException = $this->getException($exception->getResponse()
277-
->getStatusCode())
282+
$lastException = $this->getException($statusCode)
278283
->setMessage($exception->getMessage());
279284
} catch (TypesenseClientError | HttpClientException $exception) {
280285
$this->setNodeHealthCheck($node, false);

0 commit comments

Comments
 (0)