unjs / unjs/ofetch

Client errors are not retried when 500 is not included in retryStatusCodes

Open
#495 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
5.4k
Forks
195
PR merge metrics
No merged PRs in 30d

Description

Environment

ofetch 1.4.1

Reproduction

https://stackblitz.com/edit/vitejs-vite-i5wbs4ho?file=src%2Fmain.js

Describe the bug

When retryStatusCodes does not includes error code 500, ofetch no longer retries client errors.

Additional context

Error code 500 is the generic error code for any unhandled error in the backend.
On POST requests some data may already have created when the error happens,
On other requests it usually output some error logs on the backend side, so retrying will just mess the backend logs.
So to my opinion this is not a good idea to retry backend 500 errors automatically.

I would like to be able to retry only Reverse Proxy related errors (Bad Gateway, Service unavailable, ...) and client errors.

Currently, if I exclude error 500, it no longer retries client errors which is not expected.

This behavior is due to the following line:
https://github.com/unjs/ofetch/blob/main/src/fetch.ts#L62C1-L62C81
When response is empty, the response code is resolved as 500.

Logs

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at src/fetch.ts around line 62 and reproduce the behavior with the linked StackBlitz example. Verify that omitting status 500 from retryStatusCodes still allows client errors to be retried while 500 responses are not retried.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.