]> git.ardis.lu - google-forms-comments/commitdiff
Add temporary error logging
authorArdis Lu <ardisglu@gmail.com>
Tue, 24 Jan 2023 03:09:20 +0000 (19:09 -0800)
committerArdis Lu <ardisglu@gmail.com>
Tue, 24 Jan 2023 03:09:20 +0000 (19:09 -0800)
The worker works locally but not in prod, and prod has no logs

functions/comments.js

index 5e8eb7601c7bc9a2c6652630058cbdeb621b29a8..c9ce39a250bd46d3f03138ea0e8c576dbfb89324 100644 (file)
@@ -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);
+  }
 }
This page took 0.04184 seconds and 4 git commands to generate.