Add handling for internal_failure in Gmail API error parser (#17718)

fixes TWENTY-SERVER-D3X
This commit is contained in:
neo773
2026-02-09 23:32:09 +05:30
committed by GitHub
parent 9e6f19d16e
commit 5ccf18fdf5
2 changed files with 30 additions and 0 deletions
@@ -1,3 +1,5 @@
import { GaxiosError } from 'gaxios';
import {
MessageImportDriverException,
MessageImportDriverExceptionCode,
@@ -122,6 +124,27 @@ describe('parseGmailApiError', () => {
);
});
it('should handle 500 OAuth internal_failure error', () => {
const error = new GaxiosError(
'internal_failure',
{ url: 'https://oauth2.googleapis.com/token' },
{
status: 500,
statusText: 'Internal Server Error',
data: { error: 'internal_failure' },
headers: {},
config: { url: 'https://oauth2.googleapis.com/token' },
request: { responseURL: 'https://oauth2.googleapis.com/token' },
},
);
const exception = parseGmailApiError(error);
expect(exception).toBeInstanceOf(MessageImportDriverException);
expect(exception.code).toBe(
MessageImportDriverExceptionCode.TEMPORARY_ERROR,
);
});
it('should handle 400 Bad Request with errorCodeAsString', () => {
const error = getGmailApiError({ code: 400, reason: 'badRequest' });
const exception = parseGmailApiError(error);
@@ -116,6 +116,13 @@ export const parseGmailApiError = (
MessageImportDriverExceptionCode.TEMPORARY_ERROR,
);
}
if (gmailApiError.reason === 'internal_failure') {
return new MessageImportDriverException(
`${gmailApiError.code} - ${gmailApiError.message}`,
MessageImportDriverExceptionCode.TEMPORARY_ERROR,
);
}
break;
default: