diff --git a/mon-entreprise/source/actions/companyStatusActions.ts b/mon-entreprise/source/actions/companyStatusActions.ts index 717cc0401..eaad3363e 100644 --- a/mon-entreprise/source/actions/companyStatusActions.ts +++ b/mon-entreprise/source/actions/companyStatusActions.ts @@ -85,17 +85,22 @@ const fetchCommuneDetails = async function (codeCommune: string) { export const useSetEntreprise = () => { const dispatch = useDispatch() return async (siren: string) => { - dispatch(setSiren(siren)) const companyDetails = await fetchCompanyDetails(siren) + if (companyDetails === null) { + return + } + dispatch(setSiren(siren)) dispatch( setCompanyDetails( companyDetails.categorie_juridique, companyDetails.date_creation ) ) - const communeDetails: ApiCommuneJson = await fetchCommuneDetails( - companyDetails.etablissement_siege.code_commune - ) - dispatch(addCommuneDetails(communeDetails)) + if (companyDetails.etablissement_siege) { + const communeDetails: ApiCommuneJson = await fetchCommuneDetails( + companyDetails.etablissement_siege.code_commune + ) + dispatch(addCommuneDetails(communeDetails)) + } } } diff --git a/mon-entreprise/source/api/sirene.ts b/mon-entreprise/source/api/sirene.ts index f87127acf..f1fff6c40 100644 --- a/mon-entreprise/source/api/sirene.ts +++ b/mon-entreprise/source/api/sirene.ts @@ -2,11 +2,13 @@ const isSIREN = (input: string) => /^[\s]*([\d][\s]*){9}$/.exec(input) const isSIRET = (input: string) => /^[\s]*([\d][\s]*){14}$/.exec(input) export async function fetchCompanyDetails(siren: string) { + // Le paramètre `statut_diffusion` filtre les SIREN non diffusibles, cf. + // https://github.com/betagouv/mon-entreprise/issues/1399#issuecomment-770736525 const response = await fetch( `https://entreprise.data.gouv.fr/api/sirene/v3/unites_legales/${siren.replace( /[\s]/g, '' - )}` + )}?statut_diffusion=O` ) if (!response.ok) { return null diff --git a/mon-entreprise/source/components/CompanyDetails.tsx b/mon-entreprise/source/components/CompanyDetails.tsx index df0a310f1..7d23b3a3d 100644 --- a/mon-entreprise/source/components/CompanyDetails.tsx +++ b/mon-entreprise/source/components/CompanyDetails.tsx @@ -30,6 +30,15 @@ export default function CompanyDetails({ siren, denomination }: Etablissement) { fetchCompanyDetails(siren).then(setCompany) }, [siren]) + if (company === null) { + return ( +
+ {siren}
+