fix: retry Outlook API calls on 429 throttling with backoff
Respects Retry-After header when available, otherwise uses exponential backoff (2s, 4s, 6s) for up to 3 attempts. v1.57.11 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
87aeb8ad47
commit
a5295c5dd7
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "my-weekly-todo-list",
|
||||
"version": "1.57.10",
|
||||
"version": "1.57.11",
|
||||
"description": "A web-based weekly task management application that organizes to-dos and calendar events in a single, intuitive weekly view",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
@ -152,7 +152,9 @@ export const getUpcomingEvents = async (
|
||||
'$top': '50'
|
||||
});
|
||||
|
||||
const response = await fetch(
|
||||
let response: Response | null = null;
|
||||
for (let attempt = 0; attempt < 3; attempt++) {
|
||||
response = await fetch(
|
||||
`${GRAPH_ENDPOINT}/me/calendars/${encodeURIComponent(calendarId)}/calendarView?${params.toString()}`,
|
||||
{
|
||||
headers: {
|
||||
@ -162,10 +164,20 @@ export const getUpcomingEvents = async (
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
console.error(`[OUTLOOK] Failed to fetch events for calendar ${calendarId}:`, response.status, response.statusText, errorText);
|
||||
throw new Error(`Failed to fetch events: ${response.status} ${response.statusText}`);
|
||||
if (response.status === 429) {
|
||||
const retryAfter = parseInt(response.headers.get('Retry-After') || '', 10);
|
||||
const delay = (retryAfter > 0 ? retryAfter : (attempt + 1) * 2) * 1000;
|
||||
console.warn(`[OUTLOOK] 429 throttled for calendar ${calendarId}, retrying in ${delay}ms (attempt ${attempt + 1}/3)`);
|
||||
await new Promise(r => setTimeout(r, delay));
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!response!.ok) {
|
||||
const errorText = await response!.text();
|
||||
console.error(`[OUTLOOK] Failed to fetch events for calendar ${calendarId}:`, response!.status, response!.statusText, errorText);
|
||||
throw new Error(`Failed to fetch events: ${response!.status} ${response!.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user