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

@ -17,6 +17,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'GET') {
const credentialsId = req.query.credentialsId.toString()
const auth = await getAuthenticatedGoogleClient(user.id, credentialsId)
if (!auth)
return res.status(404).send("Couldn't find credentials in database")
const response = await drive({
version: 'v3',
auth,

View File

@ -19,9 +19,12 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const spreadsheetId = req.query.id.toString()
const doc = new GoogleSpreadsheet(spreadsheetId)
doc.useOAuth2Client(
await getAuthenticatedGoogleClient(user.id, credentialsId)
)
const client = await getAuthenticatedGoogleClient(user.id, credentialsId)
if (!client)
return res
.status(404)
.send({ message: "Couldn't find credentials in database" })
doc.useOAuth2Client(client)
await doc.loadInfo()
return res.send({
sheets: (