Saisie de Code · JavaScript
Fetch with Retry
Retry failed HTTP requests with exponential backoff.
Difficulte: Intermediaire · 12 Lignes · Licence: public-domain
async function fetchRetry(url, tries = 3) {
for (let i = 0; i < tries; i++) {
try {
const res = await fetch(url);
if (res.ok) return res.json();
throw new Error(`HTTP ${res.status}`);
} catch (err) {
if (i === tries - 1) throw err;
await new Promise((r) => setTimeout(r, 2 ** i * 100));
Temps0:00
Vitesse (WPM)0.0
Précision100.0%
Erreurs0
Clavier Live
Touche Suivante: A | Dernière Touche: -
Progression: 0.0%
@
&
É
"
'
(
§
È
!
Ç
À
)
-
A
Z
E
R
T
Y
U
I
O
P
^
$
Q
S
D
F
G
H
J
K
L
M
Ù
W
X
C
V
B
N
,
;
:
=
Espace
Timed Test Leaderboard
Aucun resultat pour le moment.