From 67846c05bfdf2809519125b7155d117096813b65 Mon Sep 17 00:00:00 2001 From: neo773 <62795688+neo773@users.noreply.github.com> Date: Wed, 19 Nov 2025 18:58:00 +0530 Subject: [PATCH] revert PR 12884 (#15922) this PR never really addressed the root cause which was later addressed in the auth refactor PR so reverting this as it's also causing some errors. --- .../microsoft-calendar-get-events.service.ts | 11 ------- ...icrosoft-calendar-import-events.service.ts | 12 -------- ...calendar-account-authentication.service.ts | 1 - .../microsoft-email-alias-manager.service.ts | 11 ------- ...nected-account-refresh-tokens.exception.ts | 1 - ...onnected-account-refresh-tokens.service.ts | 2 +- .../imap/utils/parse-imap-error.util.ts | 2 +- .../microsoft-get-message-list.service.ts | 13 --------- ...microsoft-network-error-handler.service.ts | 9 ------ .../is-access-token-refreshing-error.utils.ts | 7 ----- ...essaging-account-authentication.service.ts | 1 - ...saging-import-exception-handler.service.ts | 1 - .../messaging-send-message.service.ts | 29 ++----------------- 13 files changed, 4 insertions(+), 96 deletions(-) delete mode 100644 packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils.ts diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/services/microsoft-calendar-get-events.service.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/services/microsoft-calendar-get-events.service.ts index 60fdf4271f..c10865be7b 100644 --- a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/services/microsoft-calendar-get-events.service.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/services/microsoft-calendar-get-events.service.ts @@ -6,15 +6,10 @@ import { type PageIteratorCallback, } from '@microsoft/microsoft-graph-client'; -import { - CalendarEventImportDriverException, - CalendarEventImportDriverExceptionCode, -} from 'src/modules/calendar/calendar-event-import-manager/drivers/exceptions/calendar-event-import-driver.exception'; import { parseMicrosoftCalendarError } from 'src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/utils/parse-microsoft-calendar-error.util'; import { type GetCalendarEventsResponse } from 'src/modules/calendar/calendar-event-import-manager/services/calendar-get-events.service'; import { OAuth2ClientManagerService } from 'src/modules/connected-account/oauth2-client-manager/services/oauth2-client-manager.service'; import { type ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; -import { isAccessTokenRefreshingError } from 'src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils'; @Injectable() export class MicrosoftCalendarGetEventsService { @@ -61,12 +56,6 @@ export class MicrosoftCalendarGetEventsService { nextSyncCursor: pageIterator.getDeltaLink() || '', }; } catch (error) { - if (isAccessTokenRefreshingError(error?.body)) { - throw new CalendarEventImportDriverException( - error.message, - CalendarEventImportDriverExceptionCode.TEMPORARY_ERROR, - ); - } throw parseMicrosoftCalendarError(error); } } diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/services/microsoft-calendar-import-events.service.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/services/microsoft-calendar-import-events.service.ts index 9cfa0d6a16..4b526169e4 100644 --- a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/services/microsoft-calendar-import-events.service.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/services/microsoft-calendar-import-events.service.ts @@ -2,16 +2,11 @@ import { Injectable } from '@nestjs/common'; import { type Event } from '@microsoft/microsoft-graph-types'; -import { - CalendarEventImportDriverException, - CalendarEventImportDriverExceptionCode, -} from 'src/modules/calendar/calendar-event-import-manager/drivers/exceptions/calendar-event-import-driver.exception'; import { formatMicrosoftCalendarEvents } from 'src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/utils/format-microsoft-calendar-event.util'; import { parseMicrosoftCalendarError } from 'src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/utils/parse-microsoft-calendar-error.util'; import { type FetchedCalendarEvent } from 'src/modules/calendar/common/types/fetched-calendar-event'; import { OAuth2ClientManagerService } from 'src/modules/connected-account/oauth2-client-manager/services/oauth2-client-manager.service'; import { type ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; -import { isAccessTokenRefreshingError } from 'src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils'; @Injectable() export class MicrosoftCalendarImportEventsService { @@ -44,13 +39,6 @@ export class MicrosoftCalendarImportEventsService { return formatMicrosoftCalendarEvents(events); } catch (error) { - if (isAccessTokenRefreshingError(error?.body)) { - throw new CalendarEventImportDriverException( - error.message, - CalendarEventImportDriverExceptionCode.TEMPORARY_ERROR, - ); - } - throw parseMicrosoftCalendarError(error); } } diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-account-authentication.service.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-account-authentication.service.ts index 2526d779b9..6b058f07d5 100644 --- a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-account-authentication.service.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-account-authentication.service.ts @@ -84,7 +84,6 @@ export class CalendarAccountAuthenticationService { error.message, CalendarEventImportDriverExceptionCode.TEMPORARY_ERROR, ); - case ConnectedAccountRefreshAccessTokenExceptionCode.REFRESH_ACCESS_TOKEN_FAILED: case ConnectedAccountRefreshAccessTokenExceptionCode.REFRESH_TOKEN_NOT_FOUND: case ConnectedAccountRefreshAccessTokenExceptionCode.INVALID_REFRESH_TOKEN: throw new CalendarEventImportDriverException( diff --git a/packages/twenty-server/src/modules/connected-account/email-alias-manager/drivers/microsoft/microsoft-email-alias-manager.service.ts b/packages/twenty-server/src/modules/connected-account/email-alias-manager/drivers/microsoft/microsoft-email-alias-manager.service.ts index 7015f576b2..b9126648f9 100644 --- a/packages/twenty-server/src/modules/connected-account/email-alias-manager/drivers/microsoft/microsoft-email-alias-manager.service.ts +++ b/packages/twenty-server/src/modules/connected-account/email-alias-manager/drivers/microsoft/microsoft-email-alias-manager.service.ts @@ -4,11 +4,6 @@ import { isNonEmptyString } from '@sniptt/guards'; import { OAuth2ClientManagerService } from 'src/modules/connected-account/oauth2-client-manager/services/oauth2-client-manager.service'; import { type ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; -import { - MessageImportDriverException, - MessageImportDriverExceptionCode, -} from 'src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception'; -import { isAccessTokenRefreshingError } from 'src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils'; @Injectable() export class MicrosoftEmailAliasManagerService { @@ -28,12 +23,6 @@ export class MicrosoftEmailAliasManagerService { .api('/me?$select=proxyAddresses') .get() .catch((error) => { - if (isAccessTokenRefreshingError(error?.message)) { - throw new MessageImportDriverException( - error.message, - MessageImportDriverExceptionCode.CLIENT_NOT_AVAILABLE, - ); - } throw new Error(`Failed to fetch email aliases: ${error.message}`); }); diff --git a/packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/exceptions/connected-account-refresh-tokens.exception.ts b/packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/exceptions/connected-account-refresh-tokens.exception.ts index 86aa4fdca3..908e20b646 100644 --- a/packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/exceptions/connected-account-refresh-tokens.exception.ts +++ b/packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/exceptions/connected-account-refresh-tokens.exception.ts @@ -5,7 +5,6 @@ export class ConnectedAccountRefreshAccessTokenException extends CustomException export enum ConnectedAccountRefreshAccessTokenExceptionCode { REFRESH_TOKEN_NOT_FOUND = 'REFRESH_TOKEN_NOT_FOUND', INVALID_REFRESH_TOKEN = 'INVALID_REFRESH_TOKEN', - REFRESH_ACCESS_TOKEN_FAILED = 'REFRESH_ACCESS_TOKEN_FAILED', PROVIDER_NOT_SUPPORTED = 'PROVIDER_NOT_SUPPORTED', TEMPORARY_NETWORK_ERROR = 'TEMPORARY_NETWORK_ERROR', } diff --git a/packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/services/connected-account-refresh-tokens.service.ts b/packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/services/connected-account-refresh-tokens.service.ts index 3b3853f46d..484ceb0c08 100644 --- a/packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/services/connected-account-refresh-tokens.service.ts +++ b/packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/services/connected-account-refresh-tokens.service.ts @@ -133,7 +133,7 @@ export class ConnectedAccountRefreshTokensService { case ConnectedAccountProvider.IMAP_SMTP_CALDAV: throw new ConnectedAccountRefreshAccessTokenException( `Token refresh is not supported for IMAP provider for connected account ${connectedAccount.id} in workspace ${workspaceId}`, - ConnectedAccountRefreshAccessTokenExceptionCode.REFRESH_ACCESS_TOKEN_FAILED, + ConnectedAccountRefreshAccessTokenExceptionCode.PROVIDER_NOT_SUPPORTED, ); default: return assertUnreachable( diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-error.util.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-error.util.ts index 97e278e025..7999b5620e 100644 --- a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-error.util.ts +++ b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-error.util.ts @@ -20,7 +20,7 @@ export const parseImapError = ( if (error.message.includes('Connection not available')) { return new MessageImportDriverException( `IMAP client not available: ${error.message}`, - MessageImportDriverExceptionCode.CLIENT_NOT_AVAILABLE, + MessageImportDriverExceptionCode.TEMPORARY_ERROR, { cause: options?.cause || error }, ); } diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-get-message-list.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-get-message-list.service.ts index 9d680ae432..119218770a 100644 --- a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-get-message-list.service.ts +++ b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-get-message-list.service.ts @@ -15,7 +15,6 @@ import { MessageImportDriverExceptionCode, } from 'src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception'; import { MicrosoftMessageListFetchErrorHandler } from 'src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-message-list-fetch-error-handler.service'; -import { isAccessTokenRefreshingError } from 'src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils'; import { type GetMessageListsArgs } from 'src/modules/messaging/message-import-manager/types/get-message-lists-args.type'; import { type GetMessageListsResponse, @@ -93,12 +92,6 @@ export class MicrosoftGetMessageListService { this.logger.error( `Connected account ${connectedAccount.id}: Error fetching message list: ${JSON.stringify(error)}`, ); - if (isAccessTokenRefreshingError(error?.body)) { - throw new MessageImportDriverException( - error.message, - MessageImportDriverExceptionCode.CLIENT_NOT_AVAILABLE, - ); - } this.microsoftMessageListFetchErrorHandler.handleError(error); }); @@ -119,12 +112,6 @@ export class MicrosoftGetMessageListService { }); await pageIterator.iterate().catch((error) => { - if (isAccessTokenRefreshingError(error?.body)) { - throw new MessageImportDriverException( - error.message, - MessageImportDriverExceptionCode.CLIENT_NOT_AVAILABLE, - ); - } this.microsoftMessageListFetchErrorHandler.handleError(error); }); diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-network-error-handler.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-network-error-handler.service.ts index 302266d193..86ace1afcf 100644 --- a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-network-error-handler.service.ts +++ b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-network-error-handler.service.ts @@ -4,7 +4,6 @@ import { MessageImportDriverException, MessageImportDriverExceptionCode, } from 'src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception'; -import { isAccessTokenRefreshingError } from 'src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils'; import { isMicrosoftClientTemporaryError } from 'src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-temporary-error.utils'; @Injectable() @@ -13,14 +12,6 @@ export class MicrosoftNetworkErrorHandler { // eslint-disable-next-line @typescript-eslint/no-explicit-any public handleError(error: any): MessageImportDriverException | null { - if (isAccessTokenRefreshingError(error?.body)) { - return new MessageImportDriverException( - error.message, - MessageImportDriverExceptionCode.CLIENT_NOT_AVAILABLE, - { cause: error }, - ); - } - const isBodyString = error.body && typeof error.body === 'string'; const isTemporaryError = isBodyString && isMicrosoftClientTemporaryError(error.body); diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils.ts deleted file mode 100644 index 396688773f..0000000000 --- a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { ConnectedAccountRefreshAccessTokenExceptionCode } from 'src/modules/connected-account/refresh-tokens-manager/exceptions/connected-account-refresh-tokens.exception'; - -export const isAccessTokenRefreshingError = (body: string): boolean => { - return body.includes( - ConnectedAccountRefreshAccessTokenExceptionCode.REFRESH_ACCESS_TOKEN_FAILED, - ); -}; diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-account-authentication.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-account-authentication.service.ts index 82f561a1d8..f58f0053de 100644 --- a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-account-authentication.service.ts +++ b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-account-authentication.service.ts @@ -96,7 +96,6 @@ export class MessagingAccountAuthenticationService { error.message, MessageImportDriverExceptionCode.TEMPORARY_ERROR, ); - case ConnectedAccountRefreshAccessTokenExceptionCode.REFRESH_ACCESS_TOKEN_FAILED: case ConnectedAccountRefreshAccessTokenExceptionCode.REFRESH_TOKEN_NOT_FOUND: case ConnectedAccountRefreshAccessTokenExceptionCode.INVALID_REFRESH_TOKEN: await this.messagingMonitoringService.track({ diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-import-exception-handler.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-import-exception-handler.service.ts index 4bb42c6ff6..34e9a6f81a 100644 --- a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-import-exception-handler.service.ts +++ b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-import-exception-handler.service.ts @@ -68,7 +68,6 @@ export class MessageImportExceptionHandlerService { case MessageNetworkExceptionCode.ECONNRESET: case MessageNetworkExceptionCode.ETIMEDOUT: case MessageNetworkExceptionCode.ERR_NETWORK: - case MessageImportDriverExceptionCode.CLIENT_NOT_AVAILABLE: await this.handleTemporaryException( syncStep, messageChannel, diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-send-message.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-send-message.service.ts index ae3df05e97..97add291e7 100644 --- a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-send-message.service.ts +++ b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-send-message.service.ts @@ -8,12 +8,7 @@ import { z } from 'zod'; import { OAuth2ClientManagerService } from 'src/modules/connected-account/oauth2-client-manager/services/oauth2-client-manager.service'; import { type ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; -import { - MessageImportDriverException, - MessageImportDriverExceptionCode, -} from 'src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception'; import { ImapClientProvider } from 'src/modules/messaging/message-import-manager/drivers/imap/providers/imap-client.provider'; -import { isAccessTokenRefreshingError } from 'src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils'; import { SmtpClientProvider } from 'src/modules/messaging/message-import-manager/drivers/smtp/providers/smtp-client.provider'; import { mimeEncode } from 'src/modules/messaging/message-import-manager/utils/mime-encode.util'; @@ -130,31 +125,11 @@ export class MessagingSendMessageService { const response = await microsoftClient .api(`/me/messages`) - .post(message) - .catch((error) => { - if (isAccessTokenRefreshingError(error?.body)) { - throw new MessageImportDriverException( - error.message, - MessageImportDriverExceptionCode.CLIENT_NOT_AVAILABLE, - ); - } - throw error; - }); + .post(message); z.string().parse(response.id); - await microsoftClient - .api(`/me/messages/${response.id}/send`) - .post({}) - .catch((error) => { - if (isAccessTokenRefreshingError(error?.body)) { - throw new MessageImportDriverException( - error.message, - MessageImportDriverExceptionCode.CLIENT_NOT_AVAILABLE, - ); - } - throw error; - }); + await microsoftClient.api(`/me/messages/${response.id}/send`).post({}); break; }