async function fetchWithRetry(url, options = {}, retries = 3) {
const response = await fetch(url, options);
// If rate limited (429) and retries remain, wait and retry
if (response.status === 429 && retries > 0) {
const delay = 60000; // wait 60 seconds before retrying
await new Promise(resolve => setTimeout(resolve, delay));
return fetchWithRetry(url, options, retries - 1);
}
// If the request failed for another reason, throw an error
if (!response.ok) {
throw new Error(`Request failed with status ${response.status}`);
}
// Otherwise, return the successful response
return response;
}