| 916 | } |
| 917 | |
| 918 | async function fetchWithRetry( |
| 919 | input: URL | string, |
| 920 | init: RequestInit, |
| 921 | ): Promise<Response> { |
| 922 | const maxRetries = 3; |
| 923 | let res = await fetch(input, init); |
| 924 | for (let attempt = 1; attempt <= maxRetries && res.status >= 500; attempt++) { |
| 925 | const delay = 1000 * 2 ** (attempt - 1); // 1s, 2s, 4s |
| 926 | console.warn( |
| 927 | `Server error (${res.status}). Retrying in ${delay / 1000}s (attempt ${attempt}/${maxRetries})...`, |
| 928 | ); |
| 929 | await new Promise((resolve) => setTimeout(resolve, delay)); |
| 930 | res = await fetch(input, init); |
| 931 | } |
| 932 | return res; |
| 933 | } |
| 934 | |
| 935 | function getFormEntrySize(entry: FormDataEntryValue) { |
| 936 | if (typeof entry === "string") { |