deduplicate and add error management

This commit is contained in:
simon lehericey 2024-04-05 12:26:32 +02:00
parent 42f0b87c39
commit 2e2f4706c5
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5

View file

@ -60,21 +60,25 @@ class APIEntrepriseService
# See: https://entreprise.api.gouv.fr/developpeurs#surveillance-etat-fournisseurs
def api_insee_up?
response = Typhoeus.get("https://entreprise.api.gouv.fr/ping/insee/sirene", timeout: 1)
if response.success?
JSON.parse(response.body).fetch('status') == 'ok'
else
false
end
api_up?("https://entreprise.api.gouv.fr/ping/insee/sirene")
end
def api_djepva_up?
response = Typhoeus.get("https://entreprise.api.gouv.fr/ping/djepva/api-association", timeout: 1)
api_up?("https://entreprise.api.gouv.fr/ping/djepva/api-association")
end
private
def api_up?(url)
response = Typhoeus.get(url, timeout: 1)
if response.success?
JSON.parse(response.body).fetch('status') == 'ok'
else
false
end
rescue => e
Sentry.capture_exception(e)
false
end
end
end