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 b9a0bd0ef..3bb7c301d 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 @@ -134,7 +134,12 @@ export class MicrosoftGetMessagesService { return response.body; } - return { error: response.error }; + return { + error: { + ...response.body.error, + statusCode: response.status, + }, + }; }); } } 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 5c7560c42..0659e2e02 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 @@ -10,6 +10,13 @@ import { @Injectable() export class MicrosoftHandleErrorService { public handleMicrosoftMessageFetchError(error: GraphError): void { + if (!error.statusCode) { + throw new MessageImportDriverException( + `Microsoft Graph API unknown error: ${error}`, + MessageImportDriverExceptionCode.UNKNOWN, + ); + } + if (error.statusCode === 401) { throw new MessageImportDriverException( 'Unauthorized access to Microsoft Graph API', diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/services/message-import-exception-handler.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/services/message-import-exception-handler.service.ts index faaccee96..d942e8f2b 100644 --- a/packages/twenty-server/src/modules/messaging/message-import-manager/services/message-import-exception-handler.service.ts +++ b/packages/twenty-server/src/modules/messaging/message-import-manager/services/message-import-exception-handler.service.ts @@ -91,8 +91,10 @@ export class MessageImportExceptionHandlerService { [messageChannel.id], workspaceId, ); - - return; + throw new MessageImportException( + `Unknown error occurred multiple times while importing messages for message channel ${messageChannel.id} in workspace ${workspaceId}`, + MessageImportExceptionCode.UNKNOWN, + ); } const messageChannelRepository =