Fix messaging import (#16112)
This commit is contained in:
+9
-1
@@ -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(
|
||||
|
||||
+2
-14
@@ -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', () => {
|
||||
|
||||
+1
-4
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user