The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Microsoft Throtling error and wrongly types on our side (#11266)
Guillimd9ac66230292
diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/exceptions/microsoft-import-driver.exception.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/exceptions/microsoft-import-driver.exception.tsnew file mode 100644index 00000000000..0c362604bc6--- /dev/null+++ b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/exceptions/microsoft-import-driver.exception.ts@@ -0,0 +1,10 @@+import { CustomException } from 'src/utils/custom-exception';++export class MicrosoftImportDriverException extends CustomException {+ statusCode: number;+ constructor(message: string, code: string, statusCode: number) {+ super(message, code);+ this.statusCode = statusCode;+ this.code = code;+ }+}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.tsindex 388263728b5..7998c211a64 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@@ -80,7 +80,7 @@ export class MicrosoftGetMessagesService {const messages = parsedResponses.map((response) => {if ('error' in response) {- this.microsoftHandleErrorService.handleMicrosoftMessageFetchError(+ this.microsoftHandleErrorService.throwMicrosoftBatchError(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.tsindex 75ca905fd02..d7a0ec650fd 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@@ -4,6 +4,7 @@ import {MessageImportDriverException,MessageImportDriverExceptionCode,} from 'src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception';+import { MicrosoftImportDriverException } from 'src/modules/messaging/message-import-manager/drivers/microsoft/exceptions/microsoft-import-driver.exception';@Injectable()export class MicrosoftHandleErrorService {@@ -29,9 +30,24 @@ export class MicrosoftHandleErrorService {);}+ if (error.statusCode === 429) {+ throw new MessageImportDriverException(+ `Microsoft Graph API ${error.code} ${error.statusCode} error: ${error.message}`,+ MessageImportDriverExceptionCode.TEMPORARY_ERROR,+ );+ }+throw new MessageImportDriverException(`Microsoft driver error: ${error.message}`,MessageImportDriverExceptionCode.UNKNOWN,);}++ public throwMicrosoftBatchError(error: any): void {+ throw new MicrosoftImportDriverException(+ error.message,+ error.code,+ error.statusCode,+ );+ }}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.tsindex f31e56b7d58..66f0eeabaa9 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@@ -18,7 +18,8 @@ export enum MessageImportSyncStep {FULL_MESSAGE_LIST_FETCH = 'FULL_MESSAGE_LIST_FETCH',PARTIAL_MESSAGE_LIST_FETCH = 'PARTIAL_MESSAGE_LIST_FETCH',FULL_OR_PARTIAL_MESSAGE_LIST_FETCH = 'FULL_OR_PARTIAL_MESSAGE_LIST_FETCH',- MESSAGES_IMPORT = 'MESSAGES_IMPORT',+ MESSAGES_IMPORT_PENDING = 'MESSAGES_IMPORT_PENDING',+ MESSAGES_IMPORT_ONGOING = 'MESSAGES_IMPORT_ONGOING',}@Injectable()@@ -94,7 +95,7 @@ export class MessageImportExceptionHandlerService {workspaceId,);throw new MessageImportException(- `Unknown error occurred multiple times while importing messages for message channel ${messageChannel.id} in workspace ${workspaceId}`,+ `Unknown temporary error occurred multiple times while importing messages for message channel ${messageChannel.id} in workspace ${workspaceId}`,MessageImportExceptionCode.UNKNOWN,);}@@ -122,8 +123,8 @@ export class MessageImportExceptionHandlerService {[messageChannel.id],);break;-- case MessageImportSyncStep.MESSAGES_IMPORT:+ case MessageImportSyncStep.MESSAGES_IMPORT_PENDING:+ case MessageImportSyncStep.MESSAGES_IMPORT_ONGOING:await this.messageChannelSyncStatusService.scheduleMessagesImport([messageChannel.id,]);diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-messages-import.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-messages-import.service.tsindex 10a156bf7f6..671d0d267f9 100644--- a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-messages-import.service.ts+++ b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-messages-import.service.ts@@ -192,7 +192,7 @@ export class MessagingMessagesImportService {await this.messageImportErrorHandlerService.handleDriverException(error,- MessageImportSyncStep.MESSAGES_IMPORT,+ MessageImportSyncStep.MESSAGES_IMPORT_ONGOING,messageChannel,workspaceId,);