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:
mARTin 2026-03-23 00:47:52 +01:00
parent 87aeb8ad47
commit a5295c5dd7
2 changed files with 25 additions and 13 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "my-weekly-todo-list", "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", "description": "A web-based weekly task management application that organizes to-dos and calendar events in a single, intuitive weekly view",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@ -152,7 +152,9 @@ export const getUpcomingEvents = async (
'$top': '50' '$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()}`, `${GRAPH_ENDPOINT}/me/calendars/${encodeURIComponent(calendarId)}/calendarView?${params.toString()}`,
{ {
headers: { headers: {
@ -162,10 +164,20 @@ export const getUpcomingEvents = async (
} }
); );
if (!response.ok) { if (response.status === 429) {
const errorText = await response.text(); const retryAfter = parseInt(response.headers.get('Retry-After') || '', 10);
console.error(`[OUTLOOK] Failed to fetch events for calendar ${calendarId}:`, response.status, response.statusText, errorText); const delay = (retryAfter > 0 ? retryAfter : (attempt + 1) * 2) * 1000;
throw new Error(`Failed to fetch events: ${response.status} ${response.statusText}`); 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(); const data = await response.json();