JavaScript
1 async function fetchWithRetry(url, options = {}) {
2   const { maxRetries = 3, baseDelay = 200 } = options;
3  
4   for (let attempt = 0; attempt <= maxRetries; attempt++) {
5     try {
6       const response = await fetch(url, options);
7       if (!response.ok && attempt < maxRetries) {
8         const delay = baseDelay * Math.pow(2, attempt);
9         await new Promise(r => setTimeout(r, delay));
10         continue;
11       }
12       return response;
13     } catch (err) {
14       if (attempt === maxRetries) throw err;
15     }
16   }
17 }