diff --git a/index.js b/index.js index b36aa42f0cc653f5dfd2c7da28da8b8e600bbe7b..1a8e94100d9e5b41d6d9155495f9c82185b1f388 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}`