Plugins
Retry-After and a time limit
Honor a Retry-After header without going past a deadline.
Overloaded or slow servers can ask you to wait, or take too long to answer.
This page shows how to make retry wait as a server asks, and how to limit
the time a whole call may take.
Retry options for overloaded or slow servers
retry has two options for servers that are overloaded or slow:
retryAfter: when a retried response has aRetry-Afterheader, wait as long as it asks (Retry-After: 120, or an HTTP date) in place of the schedule's delay.truewaits up to 1 minute, and{ max }up tomax. It's off by default, so a server can't make calls wait.budget: how long the whole call may take, every attempt and wait included. No retry is made when its wait would end at or after the budget: the call ends with its last response orNetworkError. When the budget runs out during an attempt, the attempt is aborted, and the call fails withTimeoutError. Calls can override it.
Limit each attempt and the whole call
For "10 seconds per attempt, 30 seconds in all", use both timeout and a
budget:
import { } from "@monarcode/effetch";
import { , } from "@monarcode/effetch/plugins";
export class extends .<>()("Api", {
: "https://api.example.com",
: [
({ : 5, : true, : "30 seconds" }),
({ : "10 seconds" }),
],
}) {}
// Per call: api.get("/report", { plugins: { retry: { budget: "2 minutes" } } })What's next
- Change plugins for one call: give one call a longer budget or timeout.
- Plugin order: see why
timeoutgoes afterretry. - Built-in plugins: see every option
retryandtimeouttake.