Fix messaging import (#16112)

This commit is contained in:
Charles Bochet
2025-11-26 23:13:12 +01:00
committed by GitHub
parent 5d1c2a3348
commit b1d1bcb712
3 changed files with 12 additions and 19 deletions
@@ -1,5 +1,7 @@
import { Injectable, Logger } from '@nestjs/common';
import { isDefined } from 'twenty-shared/utils';
import {
MessageImportDriverException,
MessageImportDriverExceptionCode,
@@ -23,7 +25,13 @@ export class GmailMessagesImportErrorHandler {
}
if (isGmailApiBatchError(error)) {
throw parseGmailApiBatchError(error, messageExternalId);
const exception = parseGmailApiBatchError(error, messageExternalId);
if (!isDefined(exception)) {
return;
}
throw exception;
}
throw new MessageImportDriverException(
@@ -111,26 +111,14 @@ describe('parseGmailApiBatchError', () => {
const error = gmailBatchApiErrorMocks.getError(404);
const exception = parseGmailApiBatchError(error, messageExternalId);
expect(exception).toBeInstanceOf(MessageImportDriverException);
expect(exception?.code).toBe(
MessageImportDriverExceptionCode.SYNC_CURSOR_ERROR,
);
expect(exception?.message).toBe(
`${error.errors[0].message} for message with externalId: ${messageExternalId}`,
);
expect(exception).toBeUndefined();
});
it('should handle 410 Gone', () => {
const error = gmailBatchApiErrorMocks.getError(410);
const exception = parseGmailApiBatchError(error, messageExternalId);
expect(exception).toBeInstanceOf(MessageImportDriverException);
expect(exception?.code).toBe(
MessageImportDriverExceptionCode.SYNC_CURSOR_ERROR,
);
expect(exception?.message).toBe(
`${error.errors[0].message} for message with externalId: ${messageExternalId}`,
);
expect(exception).toBeUndefined();
});
it('should handle 429 Too Many Requests', () => {
@@ -43,10 +43,7 @@ export const parseGmailApiBatchError = (
case 404:
case 410:
return new MessageImportDriverException(
message,
MessageImportDriverExceptionCode.SYNC_CURSOR_ERROR,
);
return undefined;
case 429:
return new MessageImportDriverException(