HTTP Retry (TypeScript)
item / server / http
fetchWithRetry with per-attempt timeout, capped full-jitter backoff, Retry-After, HttpError on transport failure, plus RateLimiter and TTLCache. No dependencies.
- type
- item
- files
- 2
- registry deps
- none
- npm deps
- none
installs
- ~/lib/automindz/http-retry.ts
- ~/tests/http-retry.test.mts
- Wraps the platform fetch — zero dependencies, Node 22+
- Per-attempt AbortController composed with the caller's signal
- Transport failures throw HttpError(status 0); an HTTP status never does
import { fetchWithRetry, HttpError } from "@/lib/automindz/http-retry", then await fetchWithRetry(url, { method: "POST", body }, { retries: 2 }). An HTTP status never throws — a retryable status on the final attempt is returned like any other, so the caller reads res.ok and decides, as the Python twin does. A transport failure (DNS, reset, timeout) throws HttpError with status: 0, the url and the original error as cause. Defaults: 15 s per attempt, three attempts, retryOn: [408, 425, 429, 500, 502, 503, 504], full-jitter backoff from 500 ms capped at 8000 ms, Retry-After winning when sent. Each attempt gets its own AbortController composed with the caller's init.signal, so aborting the caller stops the retries at once. RateLimiter and TTLCache<T> mirror the Python names. fetch, sleep, random and now are options, which is how the shipped test runs with no network: node --test tests/http-retry.test.mts (Node 22+).
Variations
one state per section
No previews for this item yet.
