diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-get-message-list.service.dev.spec.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-get-message-list.service.dev.spec.ts index 0d506b4d6..f2d663fec 100644 --- a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-get-message-list.service.dev.spec.ts +++ b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-get-message-list.service.dev.spec.ts @@ -10,7 +10,7 @@ import { MicrosoftGetMessageListService } from './microsoft-get-message-list.ser import { MicrosoftHandleErrorService } from './microsoft-handle-error.service'; const refreshToken = 'replace-with-your-refresh-token'; -const syncCursor = 'replace-with-your-sync-cursor'; +const syncCursor = `replace-with-your-sync-cursor`; xdescribe('Microsoft dev tests : get message list service', () => { let service: MicrosoftGetMessageListService; 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 4c82f0c7c..335665346 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 @@ -12,18 +12,20 @@ import { MessageImportDriverExceptionCode, } from 'src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception'; import { MicrosoftClientProvider } from 'src/modules/messaging/message-import-manager/drivers/microsoft/providers/microsoft-client.provider'; +import { MicrosoftHandleErrorService } from 'src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-handle-error.service'; import { GetFullMessageListResponse, GetPartialMessageListResponse, } from 'src/modules/messaging/message-import-manager/services/messaging-get-message-list.service'; -// Microsoft API limit is 1000 messages per request on this endpoint -const MESSAGING_MICROSOFT_USERS_MESSAGES_LIST_MAX_RESULT = 1000; +// Microsoft API limit is 999 messages per request on this endpoint +const MESSAGING_MICROSOFT_USERS_MESSAGES_LIST_MAX_RESULT = 999; @Injectable() export class MicrosoftGetMessageListService { constructor( private readonly microsoftClientProvider: MicrosoftClientProvider, + private readonly microsoftHandleErrorService: MicrosoftHandleErrorService, ) {} public async getFullMessageList( @@ -54,7 +56,9 @@ export class MicrosoftGetMessageListService { const pageIterator = new PageIterator(microsoftClient, response, callback); - await pageIterator.iterate(); + await pageIterator.iterate().catch((error) => { + this.microsoftHandleErrorService.handleMicrosoftMessageFetchError(error); + }); return { messageExternalIds: messageExternalIds, @@ -103,7 +107,9 @@ export class MicrosoftGetMessageListService { const pageIterator = new PageIterator(microsoftClient, response, callback); - await pageIterator.iterate(); + await pageIterator.iterate().catch((error) => { + this.microsoftHandleErrorService.handleMicrosoftMessageFetchError(error); + }); return { messageExternalIds, diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-get-messages.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-get-messages.service.ts index 64cbcd06d..84201dc62 100644 --- a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-get-messages.service.ts +++ b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-get-messages.service.ts @@ -53,9 +53,7 @@ export class MicrosoftGetMessagesService { return messages; } catch (error) { - this.microsoftHandleErrorService.handleMicrosoftMessageListFetchError( - error, - ); + this.microsoftHandleErrorService.handleMicrosoftMessageFetchError(error); return []; } @@ -81,7 +79,7 @@ export class MicrosoftGetMessagesService { const messages = parsedResponses.map((response) => { if ('error' in response) { - this.microsoftHandleErrorService.handleMicrosoftMessageListFetchError( + this.microsoftHandleErrorService.handleMicrosoftMessageFetchError( response.error, ); } diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-handle-error.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-handle-error.service.ts index 4a8db7921..5c7560c42 100644 --- a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-handle-error.service.ts +++ b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-handle-error.service.ts @@ -9,7 +9,7 @@ import { @Injectable() export class MicrosoftHandleErrorService { - public handleMicrosoftMessageListFetchError(error: GraphError): void { + public handleMicrosoftMessageFetchError(error: GraphError): void { if (error.statusCode === 401) { throw new MessageImportDriverException( 'Unauthorized access to Microsoft Graph API',