diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index bf2c47f3d32..056721e6915 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -187,16 +187,16 @@ def update_siret sanitized_siret = siret_model.siret etablissement = begin APIEntrepriseService.create_etablissement(@dossier, sanitized_siret, current_user.id) - rescue => error - if error.try(:network_error?) && !APIEntrepriseService.api_up? - # TODO: notify ops - APIEntrepriseService.create_etablissement_as_degraded_mode(@dossier, sanitized_siret, current_user.id) - else - Sentry.capture_exception(error, extra: { dossier_id: @dossier.id, siret: }) - - # probably random error, invite user to retry - return render_siret_error(t('errors.messages.siret_network_error')) - end + rescue => error + if error.try(:network_error?) && !APIEntrepriseService.api_up? + # TODO: notify ops + APIEntrepriseService.create_etablissement_as_degraded_mode(@dossier, sanitized_siret, current_user.id) + else + Sentry.capture_exception(error, extra: { dossier_id: @dossier.id, siret: }) + + # probably random error, invite user to retry + return render_siret_error(t('errors.messages.siret_network_error')) + end end if etablissement.nil? diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index ac1075677fc..44853b33af8 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -282,7 +282,7 @@ stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/) .to_return(body: Rails.root.join('spec/fixtures/files/api_entreprise/status.json').read, status: 200) allow_any_instance_of(APIEntrepriseToken).to receive(:roles) - .and_return(["attestations_fiscales", "attestations_sociales", "bilans_entreprise_bdf"]) + .and_return(["attestations_fiscales", "attestations_sociales", "bilans_entreprise_bdf"]) allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(token_expired) if api_current_status_response @@ -462,7 +462,7 @@ expect(delivery).to receive(:deliver_later).with(no_args) expect(NotificationMailer).to receive(:send_en_construction_notification) - .and_return(delivery) + .and_return(delivery) subject