(...args)
| 408 | } |
| 409 | |
| 410 | export const fetchWithRetries: typeof fetch = async (...args) => { |
| 411 | const maxRetries = 3; |
| 412 | for (let numRetries = 0; numRetries < maxRetries; numRetries++) { |
| 413 | try { |
| 414 | return fetch(...args); |
| 415 | } catch (err) { |
| 416 | if (numRetries === maxRetries - 1) { |
| 417 | throw err; |
| 418 | } |
| 419 | await new Promise((resolve) => setTimeout(resolve, numRetries * 5_000)); |
| 420 | } |
| 421 | } |
| 422 | throw new Error("Max retries reached."); // this should be unreachable |
| 423 | }; |
no test coverage detected