ofetch
ofetch copied to clipboard
Add retryIf Option
Resolves #503
Summary
This PR adds support for retryCondition option for $fetch.
What’s new
- Introduces
retryCondition(context)callback for custom retry logic. - Keeps
retryStatusCodesandretryConditionindependent — retries if either is satisfied. - If
retryConditionthrows, 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';
}
});