Skip to content

Commit

Permalink
logging for syncFile export error on google drive (#2297)
Browse files Browse the repository at this point in the history
* logging for syncFile export error on google drive

* Adding google file to IGNORE LIST
  • Loading branch information
spolu authored Oct 28, 2023
1 parent e5ce30f commit ffe5340
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 11 deletions.
60 changes: 50 additions & 10 deletions connectors/src/connectors/google_drive/temporal/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -293,19 +297,55 @@ async function syncOneFile(
): Promise<boolean> {
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);
Expand Down
2 changes: 1 addition & 1 deletion connectors/src/connectors/google_drive/temporal/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);
}

Expand Down

0 comments on commit ffe5340

Please sign in to comment.