From 73d4875586712564c0da19b7c6c1b326a5e5e77d Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Thu, 17 Feb 2022 11:04:09 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Permet=20de=20d=C3=A9marrer=20l'?= =?UTF-8?q?app=20sans=20les=20variables=20d'environnement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- site/scripts/fetch-stats.js | 43 +++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/site/scripts/fetch-stats.js b/site/scripts/fetch-stats.js index de2775f89..fbf7cfab0 100644 --- a/site/scripts/fetch-stats.js +++ b/site/scripts/fetch-stats.js @@ -273,7 +273,30 @@ async function fetchUserFeedbackIssues() { } async function main() { createDataDir() + // In case we cannot fetch the release (the API is down or the Authorization + // token isn't valid) we fallback to some fake data -- it would be better to + // have a static ressource accessible without authentification. + writeInDataDir('stats.json', { + visitesJours: [], + visitesMois: [], + satisfaction: [], + retoursUtilisateurs: { + open: [], + closed: [], + }, + nbAnswersLast30days: 0, + }) try { + if ( + !process.env.ATINTERNET_API_ACCESS_KEY || + !process.env.ATINTERNET_API_SECRET_KEY || + !process.env.ZAMMAD_API_SECRET_KEY + ) { + console.log( + "Variables d'environnement manquantes : nous ne récupérons pas les statistiques d'usage" + ) + return + } const visitesJours = await fetchDailyVisits() const visitesMois = await fetchMonthlyVisits() const satisfaction = uniformiseData( @@ -296,23 +319,7 @@ async function main() { nbAnswersLast30days, }) } catch (e) { - console.error(e) - - // In case we cannot fetch the release (the API is down or the Authorization - // token isn't valid) we fallback to some fake data -- it would be better to - // have a static ressource accessible without authentification. - writeInDataDir('stats.json', { - visitesJours: [], - visitesMois: [], - satisfaction: [], - retoursUtilisateurs: { - open: [], - closed: [], - }, - nbAnswersLast30days: 0, - }) + console.log(e) } } -main().catch((e) => { - throw new Error(e) -}) +main()