diff --git a/app/models/champs/commune_champ.rb b/app/models/champs/commune_champ.rb index d7977c295..8dc7c9903 100644 --- a/app/models/champs/commune_champ.rb +++ b/app/models/champs/commune_champ.rb @@ -57,20 +57,11 @@ class Champs::CommuneChamp < Champs::TextChamp alias postal_code code_postal def name - if departement? && code? - APIGeoService.commune_name(code_departement, code).presence || safe_to_s - else - safe_to_s - end + APIGeoService.safely_normalize_city_name(code_departement, code, safe_to_s) end def to_s - if departement? && code_postal? && code? - name = APIGeoService.commune_name(code_departement, code) - name.present? ? "#{name} (#{code_postal})" : safe_to_s - else - safe_to_s - end + code_postal? ? "#{name} (#{code_postal})" : name end def code diff --git a/app/services/api_geo_service.rb b/app/services/api_geo_service.rb index d8c0f1c50..18e42f451 100644 --- a/app/services/api_geo_service.rb +++ b/app/services/api_geo_service.rb @@ -126,9 +126,6 @@ class APIGeoService return fallback if department_code.nil? || city_code.nil? commune_name(department_code, city_code) || fallback - - rescue StandardError - fallback end private diff --git a/spec/services/api_geo_service_spec.rb b/spec/services/api_geo_service_spec.rb index 95faa29ba..7dda79ec7 100644 --- a/spec/services/api_geo_service_spec.rb +++ b/spec/services/api_geo_service_spec.rb @@ -130,11 +130,5 @@ describe APIGeoService do it { is_expected.to eq('Paris') } end - - context 'with a wrong department' do - let(:department_code) { 'wrong' } - - it { is_expected.to eq('Paris') } - end end end