From ffe5340a117e78e44e749014911950eb92e2ab12 Mon Sep 17 00:00:00 2001 From: Stanislas Polu Date: Sat, 28 Oct 2023 16:48:39 +0200 Subject: [PATCH] logging for syncFile export error on google drive (#2297) * logging for syncFile export error on google drive * Adding google file to IGNORE LIST --- .../google_drive/temporal/activities.ts | 60 +++++++++++++++---- .../google_drive/temporal/client.ts | 2 +- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/connectors/src/connectors/google_drive/temporal/activities.ts b/connectors/src/connectors/google_drive/temporal/activities.ts index 136f2caae48e..6a306c163e8f 100644 --- a/connectors/src/connectors/google_drive/temporal/activities.ts +++ b/connectors/src/connectors/google_drive/temporal/activities.ts @@ -54,6 +54,10 @@ const MIME_TYPES_TO_SYNC = [ "application/vnd.google-apps.folder", ]; +const FILES_IGNORE_LIST: string[] = [ + "1HMXBdJq3A5i7SF_KaWC7nipU0YgNKsk_tmGOHumM2n0", +]; + export const statsDClient = new StatsD(); type NangoGetConnectionRes = { @@ -293,19 +297,55 @@ async function syncOneFile( ): Promise { const documentId = getDocumentId(file.id); let documentContent: string | undefined = undefined; + + if (FILES_IGNORE_LIST.includes(file.id)) { + logger.info( + { + documentId, + dataSourceConfig, + fileId: file.id, + title: file.name, + }, + `Google Drive document in ignore list, skipping` + ); + return false; + } + if (MIME_TYPES_TO_EXPORT[file.mimeType]) { const drive = await getDriveClient(oauth2client); - const res = await drive.files.export({ - fileId: file.id, - mimeType: MIME_TYPES_TO_EXPORT[file.mimeType], - }); - if (res.status !== 200) { - throw new Error( - `Error exporting Google document. status_code: ${res.status}. status_text: ${res.statusText}` + try { + const res = await drive.files.export({ + fileId: file.id, + mimeType: MIME_TYPES_TO_EXPORT[file.mimeType], + }); + if (res.status !== 200) { + logger.error( + { + documentId, + dataSourceConfig, + fileId: file.id, + title: file.name, + }, + "Error exporting Google document" + ); + throw new Error( + `Error exporting Google document. status_code: ${res.status}. status_text: ${res.statusText}` + ); + } + if (typeof res.data === "string") { + documentContent = res.data; + } + } catch (e) { + logger.error( + { + documentId, + dataSourceConfig, + fileId: file.id, + title: file.name, + }, + "Error exporting Google document" ); - } - if (typeof res.data === "string") { - documentContent = res.data; + throw e; } } else if (MIME_TYPES_TO_DOWNLOAD.includes(file.mimeType)) { const drive = await getDriveClient(oauth2client); diff --git a/connectors/src/connectors/google_drive/temporal/client.ts b/connectors/src/connectors/google_drive/temporal/client.ts index 40dd353ebf97..9472d2a93fc7 100644 --- a/connectors/src/connectors/google_drive/temporal/client.ts +++ b/connectors/src/connectors/google_drive/temporal/client.ts @@ -28,7 +28,7 @@ export async function launchGoogleDriveFullSyncWorkflow( if (fromTs) { return new Err( - new Error("Github connector does not support partial resync") + new Error("Google Drive connector does not support partial resync") ); }