From e60ba22b542d5472cc6520e3cffe5dc24b1b334d Mon Sep 17 00:00:00 2001 From: Bastien DUMONT <bdumont@grandlyon.com> Date: Tue, 2 Aug 2022 10:49:58 +0200 Subject: [PATCH] feat: throw user action needed error --- src/index.js | 1 + src/requests/insee.js | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index c6a9ac9..1d51dce 100644 --- a/src/index.js +++ b/src/index.js @@ -123,6 +123,7 @@ async function verifyUserIdentity( loginUtilisateur ) { const inseeCode = await getInseeCode(fields.postalCode) + if (!inseeCode) throw errors.USER_ACTION_NEEDED const pdl = await findUserPdl( `${baseUrl}/enedis_SDE_recherche-point/1.0`, diff --git a/src/requests/insee.js b/src/requests/insee.js index 62a23d3..b32fef4 100644 --- a/src/requests/insee.js +++ b/src/requests/insee.js @@ -12,8 +12,8 @@ const API_URL = 'https://apicarto.ign.fr/api/codes-postaux/communes' */ async function getInseeCode(postalCode, city) { try { - const response = await axios.get(`${API_URL}/${postalCode}`) log('info', `Query getInseeCode for postalCode ${postalCode} / ${city}`) + const response = await axios.get(`${API_URL}/${postalCode}`) if (response.data.length === 1) { return response.data[0].codeCommune @@ -26,6 +26,10 @@ async function getInseeCode(postalCode, city) { return filteredResponse[0].codeCommune } } catch (error) { + log( + 'error', + `Query getInseeCode failed for postalCode ${postalCode} / ${city}` + ) return null } } -- GitLab