From bd7fc2212d2093af108e36a04430e476ccf65a51 Mon Sep 17 00:00:00 2001 From: build-token <build-token> Date: Tue, 30 May 2023 09:28:19 +0000 Subject: [PATCH] publish: Merge branch '21-contains-sub-name' into 'main' generated from commit 115f436f5aa1a0dd0b36ba40a07c52158df97f4d --- index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index b36aa42..1a8e941 100644 --- a/index.js +++ b/index.js @@ -247513,13 +247513,20 @@ async function getInseeCode(postalCode, city) { sanitizeCity(commune.nomCommune).includes(parsedCity) ) + if (filteredResponse.length === 1) { + return filteredResponse[0].codeCommune + } + if (filteredResponse.length > 1) { - throw new Error( - 'Input city is not precise enough, more than one city was found' - ) + // Try to get the same length of the city input + for (const commune of filteredResponse) { + if (commune.nomCommune.length === city.length) { + return commune.codeCommune + } + } } - return filteredResponse[0].codeCommune + throw new Error('No match could be found') } } catch (error) { const errorMessage = `Query getInseeCode failed for postalCode ${postalCode} / ${city}` -- GitLab