2
0

feat(integration): ️ Improve feedback on GSheets errors

This commit is contained in:
Baptiste Arnaud
2022-03-04 14:40:13 +01:00
parent 9b8f153579
commit d13ca0fa9a
6 changed files with 45 additions and 16 deletions

View File

@ -23,7 +23,10 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
)
if (!extractingColumns) return badRequest(res)
const doc = new GoogleSpreadsheet(spreadsheetId)
doc.useOAuth2Client(await getAuthenticatedGoogleClient(credentialsId))
const client = await getAuthenticatedGoogleClient(credentialsId)
if (!client)
return res.status(404).send("Couldn't find credentials in database")
doc.useOAuth2Client(client)
await doc.loadInfo()
const sheet = doc.sheetsById[sheetId]
const rows = await sheet.getRows()
@ -48,7 +51,10 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
values: { [key: string]: string }
}
const doc = new GoogleSpreadsheet(spreadsheetId)
doc.useOAuth2Client(await getAuthenticatedGoogleClient(credentialsId))
const auth = await getAuthenticatedGoogleClient(credentialsId)
if (!auth)
return res.status(404).send("Couldn't find credentials in database")
doc.useOAuth2Client(auth)
await doc.loadInfo()
const sheet = doc.sheetsById[sheetId]
await sheet.addRow(values)
@ -65,7 +71,10 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
values: { [key: string]: string }
}
const doc = new GoogleSpreadsheet(spreadsheetId)
doc.useOAuth2Client(await getAuthenticatedGoogleClient(credentialsId))
const auth = await getAuthenticatedGoogleClient(credentialsId)
if (!auth)
return res.status(404).send("Couldn't find credentials in database")
doc.useOAuth2Client(auth)
await doc.loadInfo()
const sheet = doc.sheetsById[sheetId]
const rows = await sheet.getRows()