From 5914a89df24ffcfc214b2b3dfa54acabe7957db4 Mon Sep 17 00:00:00 2001 From: Guillim Date: Mon, 2 Jun 2025 14:46:36 +0200 Subject: [PATCH] Catching temporary errors in microsft batch calls (#12409) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 🐛 Improve Microsoft Graph API Temporary Error Handling on PARSE method fixes Sentry error Screenshot 2025-06-02 at 14 39 19 ### What: Enhances error handling for Microsoft Graph API batch calls ### How: by treating HTTP 503 (Service Unavailable) as temporary errors alongside existing 429 (Rate Limit) handling. ### Additional: improving logging Fixes https://github.com/twentyhq/twenty/issues/12257 --- .../microsoft/services/microsoft-get-messages.service.ts | 4 ++-- .../microsoft/utils/parse-microsoft-messages-import.util.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 21c4653ab..3acedb02a 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 @@ -143,8 +143,8 @@ export class MicrosoftGetMessagesService { return response.body; } - if (!response.body) { - this.logger.error(`No body found for response`, response); + if (response.status !== 503 && response.status !== 429) { + this.logger.error(`Microsoft parseBatchResponse error`, response); } const errorParsed = response?.body?.error diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/utils/parse-microsoft-messages-import.util.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/utils/parse-microsoft-messages-import.util.ts index 37d2c3797..ac443a89f 100644 --- a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/utils/parse-microsoft-messages-import.util.ts +++ b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/utils/parse-microsoft-messages-import.util.ts @@ -40,7 +40,7 @@ export const parseMicrosoftMessagesImportError = (error: { } } - if (error.statusCode === 429) { + if (error.statusCode === 429 || error.statusCode === 503) { return new MessageImportDriverException( `Microsoft Graph API ${error.code} ${error.statusCode} error: ${error.message}`, MessageImportDriverExceptionCode.TEMPORARY_ERROR,