Type Alias RetryMiddleware

RetryMiddleware: ((options?: RetryOptions) => ConfiguredMiddleware)

💡 By default, the request will be retried if the response status is not in the 2xx range.

// Replace the default condition with a custom one to avoid retrying on 4xx errors:
until: (response, error) => response && (response.ok || (response.status >= 400 && response.status < 500))
import wretch from 'wretch'
import { retry } from 'wretch/middlewares'

wretch().middlewares([
retry({
// Options - defaults below
delayTimer: 500,
delayRamp: (delay, nbOfAttempts) => delay * nbOfAttempts,
maxAttempts: 10,
until: (response, error) => response && response.ok,
onRetry: null,
retryOnNetworkError: false,
resolveWithLatestResponse: false,
skip: undefined
})
])

// You can also return a Promise, which is useful if you want to inspect the body:
wretch().middlewares([
retry({
until: response =>
response.clone().json().then(body =>
body.field === 'something'
)
})
])