Skip to content

Commit

Permalink
parrallelize
Browse files Browse the repository at this point in the history
  • Loading branch information
PopDaph committed Nov 22, 2023
1 parent dc9f91d commit 2a9e2f1
Showing 1 changed file with 38 additions and 29 deletions.
67 changes: 38 additions & 29 deletions connectors/src/connectors/google_drive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,35 +61,44 @@ export async function createGoogleDriveConnector(
const driveClient = await getDriveClient(nangoConnectionId);

// Sanity checks to confirm we have sufficient permissions
const sanityCheckAbout = await driveClient.about.get({ fields: "*" });
if (sanityCheckAbout.status !== 200) {
throw new Error(
`Could not get google drive info. Error message: ${
sanityCheckAbout.statusText || "unknown"
}`
);
}
const sanityCheckFilesGet = await driveClient.files.get({
fileId: "root",
});
if (sanityCheckFilesGet.status !== 200) {
throw new Error(
`Could not call google drive files get. Error message: ${
sanityCheckFilesGet.statusText || "unknown"
}`
);
}
const sanityCheckFilesList = await driveClient.drives.list({
pageSize: 10,
fields: "nextPageToken, drives(id, name)",
});
if (sanityCheckFilesList.status !== 200) {
throw new Error(
`Could not call google drive files list. Error message: ${
sanityCheckFilesList.statusText || "unknown"
}`
);
}
Promise.all([
driveClient.about.get({ fields: "*" }),
driveClient.files.get({ fileId: "root" }),
driveClient.drives.list({
pageSize: 10,
fields: "nextPageToken, drives(id, name)",
}),
])
.then(
([sanityCheckAbout, sanityCheckFilesGet, sanityCheckFilesList]) => {
if (sanityCheckAbout.status !== 200) {
throw new Error(
`Could not get google drive info. Error message: ${
sanityCheckAbout.statusText || "unknown"
}`
);
}
if (sanityCheckFilesGet.status !== 200) {
throw new Error(
`Could not call google drive files get. Error message: ${
sanityCheckFilesGet.statusText || "unknown"
}`
);
}
if (sanityCheckFilesList.status !== 200) {
throw new Error(
`Could not call google drive files list. Error message: ${
sanityCheckFilesList.statusText || "unknown"
}`
);
}
}
)
.catch(() => {
throw new Error(
"Error trying to check sufficient permissions from Google."
);
});

const connector = await Connector.create(
{
Expand Down

0 comments on commit 2a9e2f1

Please sign in to comment.