Merge branch 'dev' into main
This commit is contained in:
10
index.js
10
index.js
@@ -33,7 +33,7 @@ app.use('/rep', async (req, res) => {
|
|||||||
// If the query doesn't contain the required params...
|
// If the query doesn't contain the required params...
|
||||||
if (!lat || !lon) {
|
if (!lat || !lon) {
|
||||||
res.status(401).json({
|
res.status(401).json({
|
||||||
"message": "The request is missing geolocation data. You must use 'lat' and 'lon' in your query."
|
"message": "La requête doit contenir une latitude et une longitude pour récupérer les données de votre député."
|
||||||
});
|
});
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -45,18 +45,18 @@ app.use('/rep', async (req, res) => {
|
|||||||
const closestCity = await (await fetch(
|
const closestCity = await (await fetch(
|
||||||
`https://geo.api.gouv.fr/communes?lat=${lat}&lon=${lon}`
|
`https://geo.api.gouv.fr/communes?lat=${lat}&lon=${lon}`
|
||||||
)).json();
|
)).json();
|
||||||
let codeDepartement = String(closestCity[0].codeDepartement)
|
let codeDepartement = closestCity[0]?.codeDepartement
|
||||||
|
|
||||||
// If somehow, the gov api can't find the nearest city...
|
// If somehow, the gov api can't find the nearest city...
|
||||||
if (!codeDepartement || codeDepartement === "") {
|
if (!codeDepartement || codeDepartement === "") {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
"message": "The geolocation wasn't able to pinpoint the region the coords were in."
|
"message": "Les coordonnées de géolocalisation ne sont pas correctes ; vérifiez votre navigateur ou contactez l'administrateur du site si vous pensez qu'il s'agit d'une erreur."
|
||||||
});
|
});
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changes dep code to format of filenames on server, ie "075"
|
// 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
|
// Gets the associated features with a read and parse stream
|
||||||
const pathToFeatures = join(__dirname, `public/cirs/${codeDepartement}.json`)
|
const pathToFeatures = join(__dirname, `public/cirs/${codeDepartement}.json`)
|
||||||
@@ -78,7 +78,7 @@ app.use('/rep', async (req, res) => {
|
|||||||
// If no code is found, send a 404
|
// If no code is found, send a 404
|
||||||
if (!code) {
|
if (!code) {
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
"message": "The requested data couldn't be found. Maybe it was moved or the data isn't generated properly."
|
"message": "Impossible de trouver la circonscription demandée. Veuillez contacter l'administrateur du site si vous pensez qu'il s'agit d'une erreur."
|
||||||
});
|
});
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user