Retry Once
On network failure, try the same request one more time — keep it simple.
Flaky networks sometimes fail once. A single retry can help. Do not retry forever, and prefer not retrying clear HTTP 4xx errors. This lab forces a bad host first (optional), then a real GET.
Attempt log appears here.
Important JavaScript
async function fetchOnce(url) {
const response = await fetch(url);
if (!response.ok) {
throw new Error("HTTP " + response.status);
}
return response.json();
}
async function fetchWithRetry(url) {
try {
return await fetchOnce(url);
} catch (error) {
if (String(error.message).indexOf("HTTP ") === 0) {
throw error; // do not retry clear HTTP errors
}
return fetchOnce(url); // one network retry
}
}