You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
async/retry: only retry on certain types of errors #6196
Is your feature request related to a problem? Please describe.
A common use case of async/retry is when fetching data from an API, which has various error scenarios:
5xx error: server-side error, retriable
429 error: too many requests, retriable
Other 4xx error: other client-side error, not retriable
Various non-HTTP-status errors, pretend they don't exist to simplify this example
Describe the solution you'd like
An option called something like isRetriable that can be provided a callback to check whether to retry a given error.
classHttpErrorextendsError{constructor(publicstatus: number){super()}}// retry only if the status indicates it's retriable, otherwise reject immediatelyconstres=awaitretry(async()=>{constres=awaitfetch('https://example.com/api/endpoint')if(!res.ok)thrownewHttpError(res.status)returnres},{isRetriable: (e)=>einstanceofHttpError&&(e.status===429||e.status>=500),})
Activity
feat(async): add `isRetriable` option to `retry` (denoland#6196)
feat(async): add `isRetriable` option to `retry` (denoland#6196)