better logging of calendar failures (#12431)

better logging to troubleshoot calendar events failure :

```
[Nest] 1  -  [GoogleCalendarGetEventsService] Error: internal_failure
```
This commit is contained in:
Guillim
2025-06-03 14:23:36 +02:00
committed by GitHub
parent 278a7baf5e
commit a8eacd30a1
4 changed files with 33 additions and 11 deletions

View File

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

View File

@ -1,3 +1,5 @@
import { Logger } from '@nestjs/common';
import { GaxiosError } from 'gaxios'; import { GaxiosError } from 'gaxios';
import { import {
@ -9,6 +11,7 @@ import { MessageNetworkExceptionCode } from 'src/modules/messaging/message-impor
export const parseGaxiosError = ( export const parseGaxiosError = (
error: GaxiosError, error: GaxiosError,
): CalendarEventImportDriverException => { ): CalendarEventImportDriverException => {
const logger = new Logger(parseGaxiosError.name);
const { code } = error; const { code } = error;
switch (code) { switch (code) {
@ -23,6 +26,8 @@ export const parseGaxiosError = (
); );
default: default:
logger.error(error);
return new CalendarEventImportDriverException( return new CalendarEventImportDriverException(
error.message, error.message,
CalendarEventImportDriverExceptionCode.UNKNOWN_NETWORK_ERROR, CalendarEventImportDriverExceptionCode.UNKNOWN_NETWORK_ERROR,

View File

@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { OAuth2Client } from 'google-auth-library'; import { OAuth2Client } from 'google-auth-library';
import { google } from 'googleapis'; import { google } from 'googleapis';
@ -7,7 +7,10 @@ import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twent
@Injectable() @Injectable()
export class GoogleOAuth2ClientManagerService { export class GoogleOAuth2ClientManagerService {
constructor(private readonly twentyConfigService: TwentyConfigService) {} constructor(
private readonly twentyConfigService: TwentyConfigService,
private readonly logger: Logger,
) {}
public async getOAuth2Client(refreshToken: string): Promise<OAuth2Client> { public async getOAuth2Client(refreshToken: string): Promise<OAuth2Client> {
const gmailClientId = this.twentyConfigService.get('AUTH_GOOGLE_CLIENT_ID'); const gmailClientId = this.twentyConfigService.get('AUTH_GOOGLE_CLIENT_ID');
@ -15,15 +18,24 @@ export class GoogleOAuth2ClientManagerService {
'AUTH_GOOGLE_CLIENT_SECRET', 'AUTH_GOOGLE_CLIENT_SECRET',
); );
const oAuth2Client = new google.auth.OAuth2( try {
gmailClientId, const oAuth2Client = new google.auth.OAuth2(
gmailClientSecret, gmailClientId,
); gmailClientSecret,
);
oAuth2Client.setCredentials({ oAuth2Client.setCredentials({
refresh_token: refreshToken, refresh_token: refreshToken,
}); });
return oAuth2Client; return oAuth2Client;
} catch (error) {
this.logger.error(
`Error in ${GoogleOAuth2ClientManagerService.name}`,
error,
);
throw error;
}
} }
} }

View File

@ -1,4 +1,4 @@
import { Module } from '@nestjs/common'; import { Logger, Module } from '@nestjs/common';
import { GoogleOAuth2ClientManagerService } from 'src/modules/connected-account/oauth2-client-manager/drivers/google/google-oauth2-client-manager.service'; import { GoogleOAuth2ClientManagerService } from 'src/modules/connected-account/oauth2-client-manager/drivers/google/google-oauth2-client-manager.service';
import { MicrosoftOAuth2ClientManagerService } from 'src/modules/connected-account/oauth2-client-manager/drivers/microsoft/microsoft-oauth2-client-manager.service'; import { MicrosoftOAuth2ClientManagerService } from 'src/modules/connected-account/oauth2-client-manager/drivers/microsoft/microsoft-oauth2-client-manager.service';
@ -10,6 +10,7 @@ import { OAuth2ClientManagerService } from 'src/modules/connected-account/oauth2
OAuth2ClientManagerService, OAuth2ClientManagerService,
GoogleOAuth2ClientManagerService, GoogleOAuth2ClientManagerService,
MicrosoftOAuth2ClientManagerService, MicrosoftOAuth2ClientManagerService,
Logger,
], ],
exports: [OAuth2ClientManagerService, MicrosoftOAuth2ClientManagerService], exports: [OAuth2ClientManagerService, MicrosoftOAuth2ClientManagerService],
}) })