Skip to content

The open alternative to Salesforce, designed for AI.

[Microsoft Outlook] fix + error handling (#9696)

Guillimb2a0eb6620d7
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 0d506b4d651..f2d663fec7f 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 4c82f0c7c52..335665346af 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 64cbcd06d8e..84201dc6279 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 4a8db792195..5c7560c425b 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',