From 90ecf450b4c2b0aee225ed1a3a6a92cdeadef1f7 Mon Sep 17 00:00:00 2001 From: alma Date: Wed, 14 Jan 2026 20:32:28 +0100 Subject: [PATCH] Agenda refactor --- lib/services/caldav-sync.ts | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/services/caldav-sync.ts b/lib/services/caldav-sync.ts index 0e093b7..ba2405d 100644 --- a/lib/services/caldav-sync.ts +++ b/lib/services/caldav-sync.ts @@ -68,9 +68,38 @@ export async function discoverInfomaniakCalendars( logger.debug('CalDAV client created, attempting to list directory contents'); // List all calendars using PROPFIND on root - const items = await client.getDirectoryContents('/'); - - logger.debug(`Successfully retrieved ${items.length} items from CalDAV server`); + let items; + try { + items = await client.getDirectoryContents('/'); + logger.debug(`Successfully retrieved ${items.length} items from CalDAV server`); + } catch (dirError: any) { + // Log more details about the error + const errorDetails: any = { + email, + error: dirError?.message || String(dirError), + status: dirError?.status, + statusText: dirError?.statusText, + }; + + // Try to extract more details from the error + if (dirError?.response) { + errorDetails.responseStatus = dirError.response.status; + errorDetails.responseStatusText = dirError.response.statusText; + errorDetails.responseHeaders = dirError.response.headers; + } + + // Check if it's a 401 error specifically + if (dirError?.status === 401 || dirError?.response?.status === 401) { + logger.error('CalDAV authentication failed (401 Unauthorized)', { + ...errorDetails, + hint: 'This usually means: 1) Password is incorrect, 2) Password has changed, 3) 2FA is enabled and requires an app-specific password, 4) Account credentials are invalid', + }); + } else { + logger.error('Error listing directory contents', errorDetails); + } + + throw dirError; + } const calendars: CalDAVCalendar[] = [];