deduplicate and add error management
This commit is contained in:
parent
42f0b87c39
commit
2e2f4706c5
1 changed files with 11 additions and 7 deletions
|
@ -60,21 +60,25 @@ class APIEntrepriseService
|
||||||
|
|
||||||
# See: https://entreprise.api.gouv.fr/developpeurs#surveillance-etat-fournisseurs
|
# See: https://entreprise.api.gouv.fr/developpeurs#surveillance-etat-fournisseurs
|
||||||
def api_insee_up?
|
def api_insee_up?
|
||||||
response = Typhoeus.get("https://entreprise.api.gouv.fr/ping/insee/sirene", timeout: 1)
|
api_up?("https://entreprise.api.gouv.fr/ping/insee/sirene")
|
||||||
if response.success?
|
|
||||||
JSON.parse(response.body).fetch('status') == 'ok'
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def api_djepva_up?
|
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?
|
if response.success?
|
||||||
JSON.parse(response.body).fetch('status') == 'ok'
|
JSON.parse(response.body).fetch('status') == 'ok'
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
rescue => e
|
||||||
|
Sentry.capture_exception(e)
|
||||||
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue