Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions src/ApiCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,26 +266,40 @@ private function makeRequest(string $method, string $endPoint, bool $asJson, arr
->getContents(), true, 512, JSON_THROW_ON_ERROR) : $response->getBody()
->getContents();
} catch (HttpException $exception) {
if (
$exception->getResponse()
->getStatusCode() === 408
) {
$statusCode = $exception->getResponse()->getStatusCode();

// Skip 408 timeouts and continue to next iteration
if ($statusCode === 408) {
continue;
}

// For 4xx errors, don't retry - throw immediately
if (400 <= $statusCode && $statusCode < 500) {
$this->setNodeHealthCheck($node, false);
throw $this->getException($statusCode)
->setMessage($exception->getMessage());
}

// For 5xx errors, set exception and continue to retry logic
$this->setNodeHealthCheck($node, false);
throw $this->getException($exception->getResponse()
->getStatusCode())
$lastException = $this->getException($statusCode)
->setMessage($exception->getMessage());
} catch (TypesenseClientError | HttpClientException $exception) {
} catch (HttpClientException $exception) {
// For network errors, set exception and continue to retry logic
$this->setNodeHealthCheck($node, false);
throw $exception;
$lastException = $exception;
} catch (Exception $exception) {
if ($exception instanceof TypesenseClientError) {
throw $exception;
}

$this->setNodeHealthCheck($node, false);
$lastException = $exception;
if ($numRetries < $this->config->getNumRetries() + 1) {
sleep($this->config->getRetryIntervalSeconds());
}
}

if ($numRetries < $this->config->getNumRetries() + 1) {
usleep((int) ($this->config->getRetryIntervalSeconds() * 10**6));
}
}

if ($lastException) {
Expand Down
Loading