From 5476879f77b43a732efa92d567b43f136cd496a5 Mon Sep 17 00:00:00 2001 From: neo773 <62795688+neo773@users.noreply.github.com> Date: Thu, 20 Nov 2025 21:02:44 +0530 Subject: [PATCH] Handle Microsoft calendar sync cursor error (#15938) Resolves https://twenty-v7.sentry.io/issues/6567295627 --- .../calendar-event-import-driver.exception.ts | 1 + .../parse-microsoft-calendar-error.util.ts | 6 ++++++ ...ar-event-import-exception-handler.service.ts | 17 +++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/exceptions/calendar-event-import-driver.exception.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/exceptions/calendar-event-import-driver.exception.ts index f4c6c1b8ad..b805e07f55 100644 --- a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/exceptions/calendar-event-import-driver.exception.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/exceptions/calendar-event-import-driver.exception.ts @@ -6,6 +6,7 @@ export enum CalendarEventImportDriverExceptionCode { NOT_FOUND = 'NOT_FOUND', TEMPORARY_ERROR = 'TEMPORARY_ERROR', INSUFFICIENT_PERMISSIONS = 'INSUFFICIENT_PERMISSIONS', + SYNC_CURSOR_ERROR = 'SYNC_CURSOR_ERROR', UNKNOWN = 'UNKNOWN', UNKNOWN_NETWORK_ERROR = 'UNKNOWN_NETWORK_ERROR', } diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/utils/parse-microsoft-calendar-error.util.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/utils/parse-microsoft-calendar-error.util.ts index ecadb63f58..44f34dbf0d 100644 --- a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/utils/parse-microsoft-calendar-error.util.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/utils/parse-microsoft-calendar-error.util.ts @@ -33,6 +33,12 @@ export const parseMicrosoftCalendarError = ( CalendarEventImportDriverExceptionCode.NOT_FOUND, ); + case 410: + return new CalendarEventImportDriverException( + message, + CalendarEventImportDriverExceptionCode.SYNC_CURSOR_ERROR, + ); + case 429: return new CalendarEventImportDriverException( message, diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-event-import-exception-handler.service.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-event-import-exception-handler.service.ts index 39f941dd0f..b479c0d072 100644 --- a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-event-import-exception-handler.service.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-event-import-exception-handler.service.ts @@ -64,6 +64,9 @@ export class CalendarEventImportErrorHandlerService { workspaceId, ); break; + case CalendarEventImportDriverExceptionCode.SYNC_CURSOR_ERROR: + await this.handleSyncCursorErrorException(calendarChannel, workspaceId); + break; case CalendarEventImportDriverExceptionCode.UNKNOWN: case CalendarEventImportDriverExceptionCode.UNKNOWN_NETWORK_ERROR: default: @@ -76,6 +79,20 @@ export class CalendarEventImportErrorHandlerService { } } + private async handleSyncCursorErrorException( + calendarChannel: Pick, + workspaceId: string, + ): Promise { + this.logger.log( + `CalendarChannelId: ${calendarChannel.id} - Sync cursor error, resetting and rescheduling`, + ); + + await this.calendarChannelSyncStatusService.resetAndScheduleCalendarEventListFetch( + [calendarChannel.id], + workspaceId, + ); + } + private async handleTemporaryException( syncStep: CalendarEventImportSyncStep, calendarChannel: Pick<