Skip to content

Conversation

@PineappleIOnic
Copy link
Contributor

This PR adds retry functionality to the fetch client; by default, it is disabled, and maxRetries is set to 0.

If maxRetries is set to a non-0 value, the code will automatically retry requests that fail with either a 500 or 503 value up to the number of maxRetries. If the response is still 500/503, it will then return that response.

src/Client.php Outdated
while (true) {
$res = $callback();

if ($res->getStatusCode() !== 500 && $res->getStatusCode() !== 503 || $attempts >= $this->maxRetries) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make the codes configurable (setRetryStatusCodes), some clients may want to retry on different codes

src/Client.php Outdated
* @return mixed
* @throws \Exception
*/
private function retry(callable $callback): mixed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call this withRetries

@abnegate abnegate merged commit 02b12c0 into main Jan 17, 2025
3 checks passed
@abnegate abnegate deleted the feat-impl-retries branch January 17, 2025 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants