catching better internal errors from google (#12663)

Small fix to avoid unknown errors into temporary errors
This commit is contained in:
Guillim
2025-06-17 16:48:40 +02:00
committed by GitHub
parent 1cee587709
commit 0ae43f518d
4 changed files with 15 additions and 4 deletions

View File

@ -83,6 +83,7 @@ export class GoogleCalendarGetEventsService {
private handleError(error: GaxiosError) { private handleError(error: GaxiosError) {
this.logger.error( this.logger.error(
`Error in ${GoogleCalendarGetEventsService.name} - getCalendarEvents`, `Error in ${GoogleCalendarGetEventsService.name} - getCalendarEvents`,
error.code,
error, error,
); );
if ( if (

View File

@ -64,7 +64,7 @@ export const parseGoogleCalendarError = (error: {
CalendarEventImportDriverExceptionCode.INSUFFICIENT_PERMISSIONS, CalendarEventImportDriverExceptionCode.INSUFFICIENT_PERMISSIONS,
); );
case 500: case 500:
if (reason === 'backendError') { if (reason === 'backendError' || reason === 'internal_failure') {
return new CalendarEventImportDriverException( return new CalendarEventImportDriverException(
message, message,
CalendarEventImportDriverExceptionCode.TEMPORARY_ERROR, CalendarEventImportDriverExceptionCode.TEMPORARY_ERROR,

View File

@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service'; import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager'; import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
@ -21,6 +21,9 @@ export enum CalendarEventImportSyncStep {
@Injectable() @Injectable()
export class CalendarEventImportErrorHandlerService { export class CalendarEventImportErrorHandlerService {
private readonly logger = new Logger(
CalendarEventImportErrorHandlerService.name,
);
constructor( constructor(
private readonly twentyORMManager: TwentyORMManager, private readonly twentyORMManager: TwentyORMManager,
private readonly calendarChannelSyncStatusService: CalendarChannelSyncStatusService, private readonly calendarChannelSyncStatusService: CalendarChannelSyncStatusService,
@ -167,11 +170,13 @@ export class CalendarEventImportErrorHandlerService {
CalendarEventImportExceptionCode.UNKNOWN, CalendarEventImportExceptionCode.UNKNOWN,
); );
this.logger.log(exception);
this.exceptionHandlerService.captureExceptions( this.exceptionHandlerService.captureExceptions(
[calendarEventImportException], [calendarEventImportException],
{ {
additionalData: { additionalData: {
calendarChannelId: calendarChannel.id, calendarChannelId: calendarChannel.id,
exception,
}, },
workspace: { workspace: {
id: workspaceId, id: workspaceId,

View File

@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { ConnectedAccountProvider } from 'twenty-shared/types'; import { ConnectedAccountProvider } from 'twenty-shared/types';
import { assertUnreachable } from 'twenty-shared/utils'; import { assertUnreachable } from 'twenty-shared/utils';
@ -22,6 +22,10 @@ export type ConnectedAccountTokens = GoogleTokens | MicrosoftTokens;
@Injectable() @Injectable()
export class ConnectedAccountRefreshTokensService { export class ConnectedAccountRefreshTokensService {
private readonly logger = new Logger(
ConnectedAccountRefreshTokensService.name,
);
constructor( constructor(
private readonly googleAPIRefreshAccessTokenService: GoogleAPIRefreshAccessTokenService, private readonly googleAPIRefreshAccessTokenService: GoogleAPIRefreshAccessTokenService,
private readonly microsoftAPIRefreshAccessTokenService: MicrosoftAPIRefreshAccessTokenService, private readonly microsoftAPIRefreshAccessTokenService: MicrosoftAPIRefreshAccessTokenService,
@ -88,8 +92,9 @@ export class ConnectedAccountRefreshTokensService {
); );
} }
} catch (error) { } catch (error) {
this.logger.log(error);
throw new ConnectedAccountRefreshAccessTokenException( throw new ConnectedAccountRefreshAccessTokenException(
`Error refreshing tokens for connected account ${connectedAccount.id} in workspace ${workspaceId}: ${error.message} ${error?.response?.data?.error_description}`, `Error refreshing tokens for connected account ${connectedAccount.id.slice(0, 7)} in workspace ${workspaceId.slice(0, 7)}: ${error.message} ${error?.response?.data?.error_description}`,
ConnectedAccountRefreshAccessTokenExceptionCode.REFRESH_ACCESS_TOKEN_FAILED, ConnectedAccountRefreshAccessTokenExceptionCode.REFRESH_ACCESS_TOKEN_FAILED,
); );
} }