tech(APIBretagneService.clean): l'API de data.bretagne renvoie un vide quand il n'y a pas de resultat, change l'implem pour ce cas

This commit is contained in:
Martin 2023-10-19 08:50:51 +02:00
parent 3495147045
commit ffdd7ee95d

View file

@ -34,6 +34,7 @@ class APIBretagneService
def fetch_page(url:, params:, retry_count: 1) def fetch_page(url:, params:, retry_count: 1)
result = call(url:, params:) result = call(url:, params:)
case result case result
in Failure(code:, reason:) if code.in?(401..403) in Failure(code:, reason:) if code.in?(401..403)
if retry_count > 0 if retry_count > 0
@ -42,10 +43,10 @@ class APIBretagneService
else else
fail "APIBretagneService, #{reason} #{code}" fail "APIBretagneService, #{reason} #{code}"
end end
in Failure(code:) if code == 204
[]
in Success(body:) in Success(body:)
body body
else # no response gives back a 204, so we don't try to JSON.parse(nil) to avoid error
{ items: [] }
end end
end end