better logging of calendar failures (#12431)
better logging to troubleshoot calendar events failure : ``` [Nest] 1 - [GoogleCalendarGetEventsService] Error: internal_failure ```
This commit is contained in:
@ -81,6 +81,10 @@ export class GoogleCalendarGetEventsService {
|
||||
}
|
||||
|
||||
private handleError(error: GaxiosError) {
|
||||
this.logger.error(
|
||||
`Error in ${GoogleCalendarGetEventsService.name} - getCalendarEvents`,
|
||||
error,
|
||||
);
|
||||
if (
|
||||
error.code &&
|
||||
[
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
|
||||
import { GaxiosError } from 'gaxios';
|
||||
|
||||
import {
|
||||
@ -9,6 +11,7 @@ import { MessageNetworkExceptionCode } from 'src/modules/messaging/message-impor
|
||||
export const parseGaxiosError = (
|
||||
error: GaxiosError,
|
||||
): CalendarEventImportDriverException => {
|
||||
const logger = new Logger(parseGaxiosError.name);
|
||||
const { code } = error;
|
||||
|
||||
switch (code) {
|
||||
@ -23,6 +26,8 @@ export const parseGaxiosError = (
|
||||
);
|
||||
|
||||
default:
|
||||
logger.error(error);
|
||||
|
||||
return new CalendarEventImportDriverException(
|
||||
error.message,
|
||||
CalendarEventImportDriverExceptionCode.UNKNOWN_NETWORK_ERROR,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import { OAuth2Client } from 'google-auth-library';
|
||||
import { google } from 'googleapis';
|
||||
@ -7,7 +7,10 @@ import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twent
|
||||
|
||||
@Injectable()
|
||||
export class GoogleOAuth2ClientManagerService {
|
||||
constructor(private readonly twentyConfigService: TwentyConfigService) {}
|
||||
constructor(
|
||||
private readonly twentyConfigService: TwentyConfigService,
|
||||
private readonly logger: Logger,
|
||||
) {}
|
||||
|
||||
public async getOAuth2Client(refreshToken: string): Promise<OAuth2Client> {
|
||||
const gmailClientId = this.twentyConfigService.get('AUTH_GOOGLE_CLIENT_ID');
|
||||
@ -15,15 +18,24 @@ export class GoogleOAuth2ClientManagerService {
|
||||
'AUTH_GOOGLE_CLIENT_SECRET',
|
||||
);
|
||||
|
||||
const oAuth2Client = new google.auth.OAuth2(
|
||||
gmailClientId,
|
||||
gmailClientSecret,
|
||||
);
|
||||
try {
|
||||
const oAuth2Client = new google.auth.OAuth2(
|
||||
gmailClientId,
|
||||
gmailClientSecret,
|
||||
);
|
||||
|
||||
oAuth2Client.setCredentials({
|
||||
refresh_token: refreshToken,
|
||||
});
|
||||
oAuth2Client.setCredentials({
|
||||
refresh_token: refreshToken,
|
||||
});
|
||||
|
||||
return oAuth2Client;
|
||||
return oAuth2Client;
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
`Error in ${GoogleOAuth2ClientManagerService.name}`,
|
||||
error,
|
||||
);
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 { 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,
|
||||
GoogleOAuth2ClientManagerService,
|
||||
MicrosoftOAuth2ClientManagerService,
|
||||
Logger,
|
||||
],
|
||||
exports: [OAuth2ClientManagerService, MicrosoftOAuth2ClientManagerService],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user