From fa68a6a93ad387dac337e5c3af3c717a3e7bcaa1 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Sun, 30 Apr 2023 14:55:50 +0200 Subject: [PATCH] Fixed a bug where req isn't terminated with coords error --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index d6dba1b..008394c 100644 --- a/index.js +++ b/index.js @@ -45,7 +45,7 @@ app.use('/rep', async (req, res) => { const closestCity = await (await fetch( `https://geo.api.gouv.fr/communes?lat=${lat}&lon=${lon}` )).json(); - let codeDepartement = String(closestCity[0].codeDepartement) + let codeDepartement = closestCity[0]?.codeDepartement // If somehow, the gov api can't find the nearest city... if (!codeDepartement || codeDepartement === "") { @@ -56,7 +56,7 @@ app.use('/rep', async (req, res) => { } // Changes dep code to format of filenames on server, ie "075" - codeDepartement = codeDepartement.padStart(3, "0"); + codeDepartement = String(codeDepartement).padStart(3, "0"); // Gets the associated features with a read and parse stream const pathToFeatures = join(__dirname, `public/cirs/${codeDepartement}.json`)