From 389c078f3c202d28b9a59522d1fb23db5666c5cc Mon Sep 17 00:00:00 2001 From: xavier jouppe Date: Wed, 14 Aug 2024 15:43:32 +0200 Subject: [PATCH] fix: test e2e --- .../_snapshots/siren-883010316.json | 2 +- .../_snapshots/siren-908595879.json | 2 +- .../_snapshots/search-300025764.json | 200 ++++++++++++++ .../_snapshots/siren-300025764.json | 251 ++++++++++++++++++ .../_snapshots/siren-883010316.json | 6 +- .../_snapshots/siren-908595879.json | 6 +- .../clientUniteLegaleInsee/index.test.ts | 2 +- models/core/etablissement.ts | 49 ++-- models/core/unite-legale.ts | 56 ++-- 9 files changed, 509 insertions(+), 65 deletions(-) create mode 100644 clients/_test/clientSearchRechercheEntreprise/_snapshots/search-300025764.json create mode 100644 clients/_test/clientUniteLegaleInsee/_snapshots/siren-300025764.json diff --git a/clients/_test/clientAllEtablissementsInsee/_snapshots/siren-883010316.json b/clients/_test/clientAllEtablissementsInsee/_snapshots/siren-883010316.json index c941cc5e6..cd3717abc 100644 --- a/clients/_test/clientAllEtablissementsInsee/_snapshots/siren-883010316.json +++ b/clients/_test/clientAllEtablissementsInsee/_snapshots/siren-883010316.json @@ -16,7 +16,7 @@ "denomination": "", "nic": "00015", "dateCreation": "2018-05-06", - "dateDerniereMiseAJour": "2024-08-14T12:41:55.091Z", + "dateDerniereMiseAJour": "2024-08-14T13:22:31.517Z", "dateMiseAJourInsee": "2024-03-30T08:06:53.621", "dateDebutActivite": "", "dateFermeture": "2020-09-01", diff --git a/clients/_test/clientAllEtablissementsInsee/_snapshots/siren-908595879.json b/clients/_test/clientAllEtablissementsInsee/_snapshots/siren-908595879.json index d209ac7d4..3f6243553 100644 --- a/clients/_test/clientAllEtablissementsInsee/_snapshots/siren-908595879.json +++ b/clients/_test/clientAllEtablissementsInsee/_snapshots/siren-908595879.json @@ -16,7 +16,7 @@ "denomination": "", "nic": "00010", "dateCreation": "2022-01-01", - "dateDerniereMiseAJour": "2024-08-14T12:41:55.062Z", + "dateDerniereMiseAJour": "2024-08-14T13:22:31.485Z", "dateMiseAJourInsee": "2024-03-29T23:18:52.426", "dateDebutActivite": "", "dateFermeture": null, diff --git a/clients/_test/clientSearchRechercheEntreprise/_snapshots/search-300025764.json b/clients/_test/clientSearchRechercheEntreprise/_snapshots/search-300025764.json new file mode 100644 index 000000000..c0b2ea815 --- /dev/null +++ b/clients/_test/clientSearchRechercheEntreprise/_snapshots/search-300025764.json @@ -0,0 +1,200 @@ +{ + "args": { + "page": 1, + "searchTerms": "300025764", + "searchFilterParams": "" + }, + "result": { + "currentPage": 1, + "resultCount": 1, + "pageCount": 1, + "results": [ + { + "siren": "300025764", + "oldSiren": "300025764", + "siege": { + "siren": "300025764", + "siret": "30002576400048", + "oldSiret": "", + "etatAdministratif": "en activité", + "statutDiffusion": "partiellement diffusible", + "estSiege": true, + "enseigne": "[NON-DIFFUSIBLE] [NON-DIFFUSIBLE] [NON-DIFFUSIBLE]", + "denomination": "[NON-DIFFUSIBLE]", + "nic": "00048", + "dateCreation": "2019-12-23", + "dateDerniereMiseAJour": "", + "dateMiseAJourInsee": "", + "dateDebutActivite": "2019-12-23", + "dateFermeture": "", + "adresse": "[NON-DIFFUSIBLE]", + "adressePostale": "[NON-DIFFUSIBLE] [NON-DIFFUSIBLE] [NON-DIFFUSIBLE], [NON-DIFFUSIBLE]", + "codePostal": "[NON-DIFFUSIBLE]", + "commune": "RENNES", + "activitePrincipale": "68.20A", + "libelleActivitePrincipale": "Location de logements (68.20A)", + "trancheEffectif": "N", + "libelleTrancheEffectif": "", + "latitude": null, + "longitude": null, + "complements": { + "estEntrepreneurIndividuel": true, + "idFiness": [], + "idBio": [], + "idcc": [], + "idOrganismeFormation": [], + "idRge": [], + "idUai": [] + }, + "anneeTrancheEffectif": null, + "ancienSiege": false + }, + "tva": null, + "anciensSiegesSirets": [], + "statutDiffusion": "partiellement diffusible", + "etatAdministratif": "en activité", + "nomComplet": "[NON-DIFFUSIBLE]", + "chemin": "300025764", + "natureJuridique": "1000", + "libelleNatureJuridique": "Entrepreneur individuel", + "etablissements": { + "all": [ + { + "siren": "300025764", + "siret": "30002576400048", + "oldSiret": "", + "etatAdministratif": "en activité", + "statutDiffusion": "partiellement diffusible", + "estSiege": true, + "enseigne": "[NON-DIFFUSIBLE] [NON-DIFFUSIBLE] [NON-DIFFUSIBLE]", + "denomination": "[NON-DIFFUSIBLE]", + "nic": "00048", + "dateCreation": "2019-12-23", + "dateDerniereMiseAJour": "", + "dateMiseAJourInsee": "", + "dateDebutActivite": "2019-12-23", + "dateFermeture": "", + "adresse": "[NON-DIFFUSIBLE]", + "adressePostale": "[NON-DIFFUSIBLE] [NON-DIFFUSIBLE] [NON-DIFFUSIBLE], [NON-DIFFUSIBLE]", + "codePostal": "[NON-DIFFUSIBLE]", + "commune": "RENNES", + "activitePrincipale": "68.20A", + "libelleActivitePrincipale": "Location de logements (68.20A)", + "trancheEffectif": "N", + "libelleTrancheEffectif": "", + "latitude": null, + "longitude": null, + "complements": { + "estEntrepreneurIndividuel": true, + "idFiness": [], + "idBio": [], + "idcc": [], + "idOrganismeFormation": [], + "idRge": [], + "idUai": [] + }, + "anneeTrancheEffectif": null, + "ancienSiege": false + } + ], + "open": [ + { + "siren": "300025764", + "siret": "30002576400048", + "oldSiret": "", + "etatAdministratif": "en activité", + "statutDiffusion": "partiellement diffusible", + "estSiege": true, + "enseigne": "[NON-DIFFUSIBLE] [NON-DIFFUSIBLE] [NON-DIFFUSIBLE]", + "denomination": "[NON-DIFFUSIBLE]", + "nic": "00048", + "dateCreation": "2019-12-23", + "dateDerniereMiseAJour": "", + "dateMiseAJourInsee": "", + "dateDebutActivite": "2019-12-23", + "dateFermeture": "", + "adresse": "[NON-DIFFUSIBLE]", + "adressePostale": "[NON-DIFFUSIBLE] [NON-DIFFUSIBLE] [NON-DIFFUSIBLE], [NON-DIFFUSIBLE]", + "codePostal": "[NON-DIFFUSIBLE]", + "commune": "RENNES", + "activitePrincipale": "68.20A", + "libelleActivitePrincipale": "Location de logements (68.20A)", + "trancheEffectif": "N", + "libelleTrancheEffectif": "", + "latitude": null, + "longitude": null, + "complements": { + "estEntrepreneurIndividuel": true, + "idFiness": [], + "idBio": [], + "idcc": [], + "idOrganismeFormation": [], + "idRge": [], + "idUai": [] + }, + "anneeTrancheEffectif": null, + "ancienSiege": false + } + ], + "unknown": [], + "closed": [], + "nombreEtablissementsOuverts": 1, + "nombreEtablissements": 2, + "usePagination": false, + "currentEtablissementPage": 1 + }, + "activitePrincipale": "68.20A", + "libelleActivitePrincipale": "Location de logements", + "dateCreation": "1981-10-01", + "dateFermeture": "", + "dateDerniereMiseAJour": "2023-09-21T03:34:50", + "dateMiseAJourInsee": "2024-03-22T14:26:06", + "dateMiseAJourInpi": "2024-01-14T12:34:27", + "dateDebutActivite": "", + "trancheEffectif": null, + "anneeCategorieEntreprise": "2021", + "categorieEntreprise": "PME", + "anneeTrancheEffectif": null, + "complements": { + "estBio": false, + "estEss": false, + "estServicePublic": false, + "estEntrepreneurIndividuel": true, + "estEntrepreneurSpectacle": false, + "statutEntrepreneurSpectacle": null, + "estFiness": false, + "egaproRenseignee": false, + "estRge": false, + "estOrganismeFormation": false, + "estSocieteMission": false, + "estQualiopi": false, + "estAssociation": false, + "estUai": false, + "estEntrepriseInclusive": false, + "typeEntrepriseInclusive": null + }, + "association": { + "idAssociation": null, + "data": null + }, + "colter": { + "codeColter": null + }, + "listeIdcc": [], + "matchingEtablissements": [], + "nombreEtablissements": 2, + "nombreEtablissementsOuverts": 1, + "dirigeants": [ + { + "sexe": null, + "nom": "[NON-DIFFUSIBLE]", + "prenom": "[non-diffusible]", + "role": null, + "dateNaissancePartial": "", + "lieuNaissance": "" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/clients/_test/clientUniteLegaleInsee/_snapshots/siren-300025764.json b/clients/_test/clientUniteLegaleInsee/_snapshots/siren-300025764.json new file mode 100644 index 000000000..49cfb72fc --- /dev/null +++ b/clients/_test/clientUniteLegaleInsee/_snapshots/siren-300025764.json @@ -0,0 +1,251 @@ +{ + "args": "300025764", + "result": { + "siren": "300025764", + "oldSiren": "300025764", + "siege": { + "siren": "300025764", + "siret": "30002576400048", + "oldSiret": "", + "etatAdministratif": "inconnu", + "statutDiffusion": "diffusible", + "estSiege": true, + "enseigne": null, + "denomination": null, + "nic": "00048", + "dateCreation": "2019-12-31", + "dateDerniereMiseAJour": "", + "dateMiseAJourInsee": "", + "dateDebutActivite": "", + "dateFermeture": "", + "adresse": "", + "adressePostale": "", + "codePostal": "", + "commune": "", + "activitePrincipale": "", + "libelleActivitePrincipale": "", + "trancheEffectif": "", + "libelleTrancheEffectif": "", + "latitude": "", + "longitude": "", + "complements": { + "estEntrepreneurIndividuel": false, + "idFiness": [], + "idBio": [], + "idcc": [], + "idOrganismeFormation": [], + "idRge": [], + "idUai": [] + } + }, + "tva": null, + "anciensSiegesSirets": [ + "30002576400022", + "300025764null" + ], + "statutDiffusion": "partiellement diffusible", + "etatAdministratif": "en activité", + "nomComplet": "Michel SAUVAGE", + "chemin": "300025764", + "natureJuridique": "1000", + "libelleNatureJuridique": "Entrepreneur individuel", + "etablissements": { + "all": [ + { + "siren": "300025764", + "siret": "30002576400022", + "oldSiret": "30002576400022", + "etatAdministratif": "fermé", + "statutDiffusion": "partiellement diffusible", + "estSiege": false, + "enseigne": "", + "denomination": "", + "nic": "00022", + "dateCreation": "1981-10-01", + "dateDerniereMiseAJour": "2024-08-14T13:22:05.174Z", + "dateMiseAJourInsee": "2024-03-29T23:43:34.275", + "dateDebutActivite": "", + "dateFermeture": "2019-12-31", + "adresse": "ZONE ARTISANALE, AVENUE DES FONTENELLES, 35310 CHAVAGNE", + "adressePostale": "ZONE ARTISANALE, AVENUE DES FONTENELLES, 35310 CHAVAGNE", + "codePostal": "35310", + "commune": "CHAVAGNE", + "activitePrincipale": "69.20Z", + "libelleActivitePrincipale": "Activités comptables", + "trancheEffectif": null, + "libelleTrancheEffectif": "", + "latitude": "", + "longitude": "", + "complements": { + "estEntrepreneurIndividuel": false, + "idFiness": [], + "idBio": [], + "idcc": [], + "idOrganismeFormation": [], + "idRge": [], + "idUai": [] + }, + "anneeTrancheEffectif": null, + "ancienSiege": true + }, + { + "siren": "300025764", + "siret": "30002576400048", + "oldSiret": "30002576400048", + "etatAdministratif": "en activité", + "statutDiffusion": "partiellement diffusible", + "estSiege": true, + "enseigne": "", + "denomination": "", + "nic": "00048", + "dateCreation": "2019-12-23", + "dateDerniereMiseAJour": "2024-08-14T13:22:05.174Z", + "dateMiseAJourInsee": "2024-03-30T00:23:00.551", + "dateDebutActivite": "", + "dateFermeture": null, + "adresse": "APPT B407 - 4EME ETAGE, 51 BOULEVARD DE VERDUN, 35000 RENNES", + "adressePostale": "APPT B407 - 4EME ETAGE, 51 BOULEVARD DE VERDUN, 35000 RENNES", + "codePostal": "35000", + "commune": "RENNES", + "activitePrincipale": "68.20A", + "libelleActivitePrincipale": "Location de logements", + "trancheEffectif": null, + "libelleTrancheEffectif": "", + "latitude": "", + "longitude": "", + "complements": { + "estEntrepreneurIndividuel": false, + "idFiness": [], + "idBio": [], + "idcc": [], + "idOrganismeFormation": [], + "idRge": [], + "idUai": [] + }, + "anneeTrancheEffectif": null, + "ancienSiege": false + } + ], + "open": [ + { + "siren": "300025764", + "siret": "30002576400048", + "oldSiret": "30002576400048", + "etatAdministratif": "en activité", + "statutDiffusion": "partiellement diffusible", + "estSiege": true, + "enseigne": "", + "denomination": "", + "nic": "00048", + "dateCreation": "2019-12-23", + "dateDerniereMiseAJour": "2024-08-14T13:22:05.174Z", + "dateMiseAJourInsee": "2024-03-30T00:23:00.551", + "dateDebutActivite": "", + "dateFermeture": null, + "adresse": "APPT B407 - 4EME ETAGE, 51 BOULEVARD DE VERDUN, 35000 RENNES", + "adressePostale": "APPT B407 - 4EME ETAGE, 51 BOULEVARD DE VERDUN, 35000 RENNES", + "codePostal": "35000", + "commune": "RENNES", + "activitePrincipale": "68.20A", + "libelleActivitePrincipale": "Location de logements", + "trancheEffectif": null, + "libelleTrancheEffectif": "", + "latitude": "", + "longitude": "", + "complements": { + "estEntrepreneurIndividuel": false, + "idFiness": [], + "idBio": [], + "idcc": [], + "idOrganismeFormation": [], + "idRge": [], + "idUai": [] + }, + "anneeTrancheEffectif": null, + "ancienSiege": false + } + ], + "unknown": [], + "closed": [ + { + "siren": "300025764", + "siret": "30002576400022", + "oldSiret": "30002576400022", + "etatAdministratif": "fermé", + "statutDiffusion": "partiellement diffusible", + "estSiege": false, + "enseigne": "", + "denomination": "", + "nic": "00022", + "dateCreation": "1981-10-01", + "dateDerniereMiseAJour": "2024-08-14T13:22:05.174Z", + "dateMiseAJourInsee": "2024-03-29T23:43:34.275", + "dateDebutActivite": "", + "dateFermeture": "2019-12-31", + "adresse": "ZONE ARTISANALE, AVENUE DES FONTENELLES, 35310 CHAVAGNE", + "adressePostale": "ZONE ARTISANALE, AVENUE DES FONTENELLES, 35310 CHAVAGNE", + "codePostal": "35310", + "commune": "CHAVAGNE", + "activitePrincipale": "69.20Z", + "libelleActivitePrincipale": "Activités comptables", + "trancheEffectif": null, + "libelleTrancheEffectif": "", + "latitude": "", + "longitude": "", + "complements": { + "estEntrepreneurIndividuel": false, + "idFiness": [], + "idBio": [], + "idcc": [], + "idOrganismeFormation": [], + "idRge": [], + "idUai": [] + }, + "anneeTrancheEffectif": null, + "ancienSiege": true + } + ], + "nombreEtablissementsOuverts": 1, + "nombreEtablissements": 2, + "usePagination": false, + "currentEtablissementPage": 1 + }, + "activitePrincipale": "68.20A", + "libelleActivitePrincipale": "Location de logements", + "dateCreation": "1981-10-01", + "dateFermeture": "", + "dateDerniereMiseAJour": "2023-10-5", + "dateMiseAJourInsee": "2024-03-22", + "dateMiseAJourInpi": "", + "dateDebutActivite": "2019-12-31", + "trancheEffectif": null, + "anneeCategorieEntreprise": "2021", + "categorieEntreprise": "PME", + "anneeTrancheEffectif": null, + "complements": { + "estEntrepreneurIndividuel": true, + "estEss": false, + "estBio": false, + "estEntrepreneurSpectacle": false, + "egaproRenseignee": false, + "statutEntrepreneurSpectacle": "", + "estServicePublic": false, + "estFiness": false, + "estRge": false, + "estOrganismeFormation": false, + "estSocieteMission": false, + "estQualiopi": false, + "estUai": false, + "estAssociation": false, + "estEntrepriseInclusive": false, + "typeEntrepriseInclusive": "" + }, + "association": { + "idAssociation": null + }, + "colter": { + "codeColter": null + }, + "listeIdcc": [] + } +} \ No newline at end of file diff --git a/clients/_test/clientUniteLegaleInsee/_snapshots/siren-883010316.json b/clients/_test/clientUniteLegaleInsee/_snapshots/siren-883010316.json index 417a8b438..c77691ca3 100644 --- a/clients/_test/clientUniteLegaleInsee/_snapshots/siren-883010316.json +++ b/clients/_test/clientUniteLegaleInsee/_snapshots/siren-883010316.json @@ -14,7 +14,7 @@ "denomination": "", "nic": "00015", "dateCreation": "2018-05-06", - "dateDerniereMiseAJour": "2024-08-14T12:41:55.187Z", + "dateDerniereMiseAJour": "2024-08-14T13:22:31.620Z", "dateMiseAJourInsee": "2024-03-30T08:06:53.621", "dateDebutActivite": "", "dateFermeture": "2020-09-01", @@ -60,7 +60,7 @@ "denomination": "", "nic": "00015", "dateCreation": "2018-05-06", - "dateDerniereMiseAJour": "2024-08-14T12:41:55.187Z", + "dateDerniereMiseAJour": "2024-08-14T13:22:31.620Z", "dateMiseAJourInsee": "2024-03-30T08:06:53.621", "dateDebutActivite": "", "dateFermeture": "2020-09-01", @@ -101,7 +101,7 @@ "denomination": "", "nic": "00015", "dateCreation": "2018-05-06", - "dateDerniereMiseAJour": "2024-08-14T12:41:55.187Z", + "dateDerniereMiseAJour": "2024-08-14T13:22:31.620Z", "dateMiseAJourInsee": "2024-03-30T08:06:53.621", "dateDebutActivite": "", "dateFermeture": "2020-09-01", diff --git a/clients/_test/clientUniteLegaleInsee/_snapshots/siren-908595879.json b/clients/_test/clientUniteLegaleInsee/_snapshots/siren-908595879.json index a925f9b94..10c75a5d2 100644 --- a/clients/_test/clientUniteLegaleInsee/_snapshots/siren-908595879.json +++ b/clients/_test/clientUniteLegaleInsee/_snapshots/siren-908595879.json @@ -14,7 +14,7 @@ "denomination": "", "nic": "00010", "dateCreation": "2022-01-01", - "dateDerniereMiseAJour": "2024-08-14T12:41:55.101Z", + "dateDerniereMiseAJour": "2024-08-14T13:22:31.528Z", "dateMiseAJourInsee": "2024-03-29T23:18:52.426", "dateDebutActivite": "", "dateFermeture": null, @@ -60,7 +60,7 @@ "denomination": "", "nic": "00010", "dateCreation": "2022-01-01", - "dateDerniereMiseAJour": "2024-08-14T12:41:55.131Z", + "dateDerniereMiseAJour": "2024-08-14T13:22:31.559Z", "dateMiseAJourInsee": "2024-03-29T23:18:52.426", "dateDebutActivite": "", "dateFermeture": null, @@ -99,7 +99,7 @@ "denomination": "", "nic": "00010", "dateCreation": "2022-01-01", - "dateDerniereMiseAJour": "2024-08-14T12:41:55.131Z", + "dateDerniereMiseAJour": "2024-08-14T13:22:31.559Z", "dateMiseAJourInsee": "2024-03-29T23:18:52.426", "dateDebutActivite": "", "dateFermeture": null, diff --git a/clients/_test/clientUniteLegaleInsee/index.test.ts b/clients/_test/clientUniteLegaleInsee/index.test.ts index 52c359fdc..581ab53df 100644 --- a/clients/_test/clientUniteLegaleInsee/index.test.ts +++ b/clients/_test/clientUniteLegaleInsee/index.test.ts @@ -4,7 +4,7 @@ import { expectClientToMatchSnapshot } from '../expect-client-to-match-snapshot' import simplifyParams from './simplify-params'; describe('clientUniteLegaleInsee', () => { - (['908595879', '883010316'] as Siren[]).forEach( + (['908595879', '883010316', '300025764'] as Siren[]).forEach( expectClientToMatchSnapshotWithSiren ); }); diff --git a/models/core/etablissement.ts b/models/core/etablissement.ts index c23ce1ed2..d0f6cc274 100644 --- a/models/core/etablissement.ts +++ b/models/core/etablissement.ts @@ -167,7 +167,7 @@ const fetchEtablissmentFromInsee = async ( } if (!options.useFallback) { - return await clientEtablissementInsee(siret, { + return await fetchEtablissmentFromInsee(siret, { ...options, useFallback: true, }); @@ -189,34 +189,33 @@ const fetchEtablissmentFromInsee = async ( const fetchEtablissementFromRechercheEntreprise = async ( siret: Siret, - useCache = false + useCache = false, + useFallback = false ): Promise => { try { return await clientEtablissementRechercheEntreprise(siret, useCache); - } catch (firstFallback: any) { - if (!(firstFallback instanceof HttpNotFound)) { - try { - const useFallback = true; - return await clientEtablissementRechercheEntreprise( - siret, - useCache, - useFallback - ); - } catch (eFallback: any) { - if (!(eFallback instanceof HttpNotFound)) { - logFatalErrorInSentry( - new FetchEtablissementException({ - message: 'Fail to fetch from Search API', - cause: firstFallback, - administration: EAdministration.DINUM, - context: { - siret, - }, - }) - ); - } - } + } catch (e: any) { + if (e instanceof HttpNotFound) { + return APINotRespondingFactory(EAdministration.DINUM, 404); } + if (!useFallback) { + return await fetchEtablissementFromRechercheEntreprise( + siret, + useCache, + true + ); + } + + logFatalErrorInSentry( + new FetchEtablissementException({ + message: 'Fail to fetch from Search API', + cause: e, + administration: EAdministration.DINUM, + context: { + siret, + }, + }) + ); return APINotRespondingFactory(EAdministration.DINUM, 500); } diff --git a/models/core/unite-legale.ts b/models/core/unite-legale.ts index b1cc7f1da..89358cd99 100644 --- a/models/core/unite-legale.ts +++ b/models/core/unite-legale.ts @@ -16,6 +16,7 @@ import { shouldUseInsee } from '.'; import { EAdministration } from '../administrations/EAdministration'; import { APINotRespondingFactory, + IAPINotRespondingError, isAPI404, isAPINotResponding, } from '../api-not-responding'; @@ -230,8 +231,9 @@ class UniteLegaleBuilder { const fetchUniteLegaleFromRechercheEntreprise = async ( siren: Siren, pageEtablissements: number, - useCache: boolean -) => { + useCache: boolean, + useFallback = false +): Promise => { try { const useFallback = false; return await clientUniteLegaleRechercheEntreprise( @@ -244,34 +246,26 @@ const fetchUniteLegaleFromRechercheEntreprise = async ( if (e instanceof HttpNotFound) { return APINotRespondingFactory(EAdministration.DINUM, 404); } - if (!(e instanceof HttpNotFound)) { - try { - const forceFallback = true; - return await clientUniteLegaleRechercheEntreprise( - siren, - pageEtablissements, - forceFallback, - useCache - ); - } catch (eFallback: any) { - if (eFallback instanceof HttpNotFound) { - return APINotRespondingFactory(EAdministration.DINUM, 404); - } - if (!(eFallback instanceof HttpNotFound)) { - logFatalErrorInSentry( - new FetchRessourceException({ - cause: eFallback, - ressource: 'UniteLegale', - administration: EAdministration.DINUM, - context: { - siren, - }, - }) - ); - } - } + if (!useFallback) { + const forceFallback = true; + return await fetchUniteLegaleFromRechercheEntreprise( + siren, + pageEtablissements, + forceFallback, + useCache + ); } - // we dont care about the type of exception here as HttpNotFound and HttpServerError will both be useless to us + logFatalErrorInSentry( + new FetchRessourceException({ + cause: e, + ressource: 'UniteLegale', + administration: EAdministration.DINUM, + context: { + siren, + }, + }) + ); + return APINotRespondingFactory(EAdministration.DINUM, 500); } }; @@ -283,7 +277,7 @@ const fetchUniteLegaleFromInsee = async ( siren: Siren, page = 1, inseeOptions: InseeClientOptions -) => { +): Promise => { try { return await clientUniteLegaleInsee(siren, page, inseeOptions); } catch (e: any) { @@ -299,7 +293,7 @@ const fetchUniteLegaleFromInsee = async ( } if (!inseeOptions.useFallback) { - return await clientUniteLegaleInsee(siren, page, { + return await fetchUniteLegaleFromInsee(siren, page, { ...inseeOptions, useFallback: true, });