From 63d2508423f44200d4f0c1abfd781845bd1f45c3 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 15 Aug 2023 12:12:21 +0100 Subject: [PATCH 1/2] Replace throwing error with console.warn() when no train data in response --- src/pages/InsightsPage.vue | 4 ++-- src/pages/MapPage.vue | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/InsightsPage.vue b/src/pages/InsightsPage.vue index 3425ffb..f9c4efc 100644 --- a/src/pages/InsightsPage.vue +++ b/src/pages/InsightsPage.vue @@ -189,7 +189,7 @@ export default { const getTrainData = httpsCallable(functions, 'getLiveTrainData'); getTrainData().then((response) => { try { - if (!response.data) throw new Error("Error fetching live train data from the database") + if (!response.data) console.warn("No train data in response!"); var unorderedTrains = []; var insights = { "totalNumTrains": 0, @@ -405,4 +405,4 @@ td.l, th.l{ content: "Destination"; } } - \ No newline at end of file + diff --git a/src/pages/MapPage.vue b/src/pages/MapPage.vue index 62f1de6..a6c355f 100644 --- a/src/pages/MapPage.vue +++ b/src/pages/MapPage.vue @@ -415,7 +415,7 @@ export default { const getTrainData = httpsCallable(functions, 'getLiveTrainData'); getTrainData().then((response) => { try { - if (!response.data) throw new Error("Error fetching live train data from the database") + if (!response.data) console.warn("No train data in response!"); var unorderedTrains = []; var currentMessages = []; var insights = { From 3be37dad99c29a66775e9eae84e9efcbf780df40 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 15 Aug 2023 12:15:31 +0100 Subject: [PATCH 2/2] Fix logs to reflect that empty snapshot is likely not an error Additionally replace incorrect 404 message --- functions/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/functions/index.js b/functions/index.js index b60b9d8..fe5065a 100644 --- a/functions/index.js +++ b/functions/index.js @@ -20,8 +20,8 @@ exports.getStationData = functions.https.onRequest((request, response) => { // fetch the "stations" collection admin.firestore().collection('stations').get().then((snapshot) => { if (snapshot.empty) { - functions.logger.log("Error fetching station data from Firestore") - response.status(404).send({data: "Error fetching station data from Firestore"}) + functions.logger.log("Empty snapshot received when fetching station data from Firestore") + response.status(404).send({data: "Empty snapshot received when fetching station data from Firestore"}) return; } // iterate through each of the collection's documents @@ -185,8 +185,8 @@ exports.getLiveTrainData = functions.https.onRequest((request, response) => { // fetch the "liveTrainData" collection admin.firestore().collection('liveTrainData').get().then((snapshot) => { if (snapshot.empty) { - functions.logger.log("Error fetching live train data from Firestore") - response.status(404).send({data: "Successfully fetched live train data from Firestore"}); + functions.logger.log("Empty snapshot received when fetching live train data from Firestore") + response.status(404).send({data: "Empty snapshot received when fetching live train data from Firestore"}); return; } // iterate through each of the collection's documents @@ -489,4 +489,4 @@ exports.deletePreferences = functions.https.onCall((data, context) => { functions.logger.log("Successfully deleted user preferences from Firestore") return "Successfully deleted user preferences from Firestore" }) -}) \ No newline at end of file +})