Retry Engine
TypeFetch includes a built-in retry engine on the client.
client.setRetryConfig({
maxRetries: 3,
backoff: "exponential",
retryCondition: (error, attempt) => {
return error.status !== undefined && error.status >= 500;
},
});Supported backoff strategies:
| Strategy | Behavior |
|---|---|
fixed | Same delay each retry |
linear | Delay increases linearly |
exponential | Delay doubles after each retry |
Example:
client.setRetryConfig({
maxRetries: 3,
backoff: "fixed",
});Timeout and Abort Support
Each request can receive per-call options.
await api.user.getUser(
{
path: { id: "123" },
},
{
timeout: 5000,
},
);You can also pass an external AbortSignal.
const controller = new AbortController();
await api.user.getUser(
{
path: { id: "123" },
},
{
signal: controller.signal,
},
);
controller.abort();