Skip to content
Snippets Groups Projects
Commit e60ba22b authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

feat: throw user action needed error

parent e284ce29
No related branches found
No related tags found
1 merge request!9Feat/insee code
Pipeline #39664 passed
......@@ -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`,
......
......@@ -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
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment