Tasks /
TypeScript /
Request retry — TypeScript
Statement
medium
Request retry — TypeScript
The `fetchWithRetry(fetcher, url, attempts = 3)` function calls `fetcher(url)`
and retries on a `5xx` response or a thrown error. A `4xx` response is returned
immediately, without retries.
Write Vitest tests: success on the first try, `500` then success, `404` without
retries, exhausted attempts and an error after the last try.
TypeScript · Vitest
AI mentor
The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.
Log in and ask
Hints
1 of 3 unlocked · attempts: 0
Hint 1
Check not only the final result, but also the number of `fetcher` calls.
Otherwise the test cannot tell "retried" from "returned immediately".
Hint 2 — unlocks after 1 attempt
Hint 3 — unlocks after 3 attempts