From: Ardis Lu Date: Tue, 24 Jan 2023 03:09:20 +0000 (-0800) Subject: Add temporary error logging X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=dc68e79f3c84fd60cff845b4b5602c3ceddee9e7;p=google-forms-comments Add temporary error logging The worker works locally but not in prod, and prod has no logs --- diff --git a/functions/comments.js b/functions/comments.js index 5e8eb76..c9ce39a 100644 --- a/functions/comments.js +++ b/functions/comments.js @@ -60,10 +60,15 @@ async function getGoogleAuthToken(clientEmail, privateKey, scopes) { } export async function onRequestGet({ env }) { - const sheetId = '1iiIolIwByFYo3ufmVWMpiGpjMlXA3e-qXI3-XFVedSQ'; - const range = 'A2:C'; - const requestUrl = `https://sheets.googleapis.com/v4/spreadsheets/${sheetId}/values/${range}`; - const token = await getGoogleAuthToken(env.EMAIL, env.PRIVATE_KEY, 'https://www.googleapis.com/auth/spreadsheets.readonly'); + try { + const sheetId = '1iiIolIwByFYo3ufmVWMpiGpjMlXA3e-qXI3-XFVedSQ'; + const range = 'A2:C'; + const requestUrl = `https://sheets.googleapis.com/v4/spreadsheets/${sheetId}/values/${range}`; + const token = await getGoogleAuthToken(env.EMAIL, env.PRIVATE_KEY, 'https://www.googleapis.com/auth/spreadsheets.readonly'); - return fetch(requestUrl, { headers: { Authorization: `Bearer ${token}` } }); + return fetch(requestUrl, { headers: { Authorization: `Bearer ${token}` } }); + } + catch (error) { + return new Response(error); + } }