diff --git a/functions/index.js b/functions/index.js index 01e8150..1e75404 100644 --- a/functions/index.js +++ b/functions/index.js @@ -51,7 +51,18 @@ exports.processSheetScheduler = onSchedule( console.log(`skipping document: ${doc.id} as its hash%60 (${hashToSixty}) does not match the cron minute (${eventDate.getMinutes()})`); return; } - logger.log(`processing document ${doc.id}, its hash % 60 (${hashToSixty}) matches the cron minute (${eventDate.getMinutes()})`); + logger.log(`processing document ${doc.id}, its hash % 60 (${hashToSixty}) matches the cron minute (${eventDate.getMinutes()})`); + + // try to access the spreadsheet and delete the document if it's not found, users will delete/change auth on sheets and we don't want to keep processing them + try { + s3 = await gapi.client.sheets.spreadsheets.get({spreadsheetId: doc.id,}); + } catch (e) { + logger.log(e); + if (e.status == 404) { + await doc.ref.delete(); + logger.log(`document ${doc.id} not found, deleted`); + } + } // send POST request with sheetID to trigger sheet processing const url = "https://auto-archiver-api.bellingcat.com/sheet_service"; diff --git a/src/store/index.js b/src/store/index.js index 339059e..94226b0 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -342,7 +342,7 @@ export default new Vuex.Store({ ); const response = await getDocs(q); - if(response.docs.length > 0) { + if (response.docs.length > 0) { throw "Sheet already enabled"; }