Add handling for internal_failure in Gmail API error parser (#17718)
fixes TWENTY-SERVER-D3X
This commit is contained in:
+23
@@ -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);
|
||||
|
||||
+7
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user