Skip to content

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

@felicienfrancois

Description

@felicienfrancois

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions