From ffdd7ee95d0ae750ebd414606b8829cf8d57ee6f Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 19 Oct 2023 08:50:51 +0200 Subject: [PATCH] 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 --- app/services/api_bretagne_service.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/services/api_bretagne_service.rb b/app/services/api_bretagne_service.rb index e5a956f7f..1bdc0e56e 100644 --- a/app/services/api_bretagne_service.rb +++ b/app/services/api_bretagne_service.rb @@ -34,6 +34,7 @@ class APIBretagneService def fetch_page(url:, params:, retry_count: 1) result = call(url:, params:) + case result in Failure(code:, reason:) if code.in?(401..403) if retry_count > 0 @@ -42,10 +43,10 @@ class APIBretagneService else fail "APIBretagneService, #{reason} #{code}" end - in Failure(code:) if code == 204 - [] in Success(body:) body + else # no response gives back a 204, so we don't try to JSON.parse(nil) to avoid error + { items: [] } end end