unjs / ofetch

😱 A better fetch API. Works on node, browser and workers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feat: support callback for `retry` option

enkot opened this issue · comments

Describe the feature

There are situations when we need to retry the request based on the special code returned by the API.
I suggest adding support for a callback for retry option, which is a function that takes a fetch context object and count of retries and returns a boolean (true if the request needs to be retried):

await $fetch('/cart', {
  retry: (ctx, count) => {
    return count <= 3 && ctx.error.code === '007'
  }
})

Additional information

  • Would you be willing to help implement this feature?