ofetch icon indicating copy to clipboard operation
ofetch copied to clipboard

Add retryIf Option

Open faizanu94 opened this issue 4 months ago • 3 comments

Resolves #503

Summary

This PR adds support for retryCondition option for $fetch.

What’s new

  • Introduces retryCondition(context) callback for custom retry logic.
  • Keeps retryStatusCodes and retryCondition independent — retries if either is satisfied.
  • If retryCondition throws, the error is propagated to the consumer.
  • Functionality is verified via unit tests

Example

await $fetch('/api/data', {
  retry: 3,
  retryCondition: (ctx) => {
    // Retry until response body contains expected field
    return ctx.response?._data?.status !== 'ready';
  }
});

faizanu94 avatar Sep 19 '25 21:09 faizanu94