diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 23ca45641..8e175d8b2 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -86,8 +86,7 @@ class Users::DossiersController < UsersController end rescue RestClient::ResourceNotFound, RestClient::BadRequest errors_valid_siret - rescue RestClient::ServiceUnavailable - render '/dossiers/degraded', formats: 'js' + rescue ActiveRecord::RecordNotFound flash.alert = t('errors.messages.dossier_not_found') redirect_to url_for users_dossiers_path diff --git a/app/services/dossier_service.rb b/app/services/dossier_service.rb index e66b0d814..01c1fc6a0 100644 --- a/app/services/dossier_service.rb +++ b/app/services/dossier_service.rb @@ -7,14 +7,10 @@ class DossierService end def dossier_informations! - @entreprise_adapter = SIADE::EntrepriseAdapter.new(DossierService.siren @siret).to_params + @entreprise_adapter = SIADE::EntrepriseAdapter.new(DossierService.siren @siret) - if @entreprise_adapter[:http_code] == 404 + if @entreprise_adapter.to_params.nil? raise RestClient::ResourceNotFound - elsif @entreprise_adapter[:http_code] == 503 || - @entreprise_adapter[:http_code] == 500 || - @entreprise_adapter[:http_code] == 400 - raise RestClient::ServiceUnavailable end @etablissement_adapter = SIADE::EtablissementAdapter.new(@siret) @@ -38,6 +34,7 @@ class DossierService @dossier end + def self.siren siret siret[0..8] end diff --git a/app/views/dossiers/degraded.js.erb b/app/views/dossiers/degraded.js.erb deleted file mode 100644 index 72bc9737a..000000000 --- a/app/views/dossiers/degraded.js.erb +++ /dev/null @@ -1,13 +0,0 @@ -<% if flash.empty? %> -$('.row.etape.etape_2').hide(300, render_new_siret); -$('.row.etape.etape_2').slideDown(400, the_terms); -toggle_etape_1(); -<% else %> -error_form_siret('<%= invalid_siret %>'); -<% end %> - -<% flash.clear %> - -function render_new_siret(){ - $('.row.etape.etape_2').html("<%= escape_javascript(render partial: '/dossiers/etapes/etape2_degraded', locals: { facade: @facade } ) %>"); -} \ No newline at end of file diff --git a/app/views/dossiers/etapes/_etape2_degraded.html.haml b/app/views/dossiers/etapes/_etape2_degraded.html.haml deleted file mode 100644 index df0db13b6..000000000 --- a/app/views/dossiers/etapes/_etape2_degraded.html.haml +++ /dev/null @@ -1 +0,0 @@ -= render partial: 'dossiers/etapes/etape_2/degraded' \ No newline at end of file diff --git a/app/views/dossiers/etapes/etape_2/_degraded.html.haml b/app/views/dossiers/etapes/etape_2/_degraded.html.haml deleted file mode 100644 index eb8324425..000000000 --- a/app/views/dossiers/etapes/etape_2/_degraded.html.haml +++ /dev/null @@ -1,23 +0,0 @@ -.etape.etapes_menu.col-md-3.col-lg-3 - %h3 - Mes informations - %br - -.etape.etapes_informations.col-md-9.col-lg-9 - .row - #recap_info_entreprise - %h3.text-warning - INSEE Indisponible - - %p - %b - Notre partenaire l'INSEE est actuellement indisponible. Nous ne pouvons donc pas récupérer les informations de votre entreprise. Une fois de retour, vos informations seront automatiquement ajoutées à votre dossier. - - %br - = form_for @facade.dossier, url: { controller: '/users/dossiers', action: :update } do |f| - = f.hidden_field :id - %label{ style:'font-weight:normal' } - = f.check_box :autorisation_donnees - J'autorise les décideurs publics à vérifier les informations de mon organisation auprès des administrations concernées. Ces informations resteront strictement confidentielles. - %br - = f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float:right', id: 'etape_suivante', disabled: :disabled diff --git a/lib/siade/entreprise_adapter.rb b/lib/siade/entreprise_adapter.rb index 50c5e1774..d926ae189 100644 --- a/lib/siade/entreprise_adapter.rb +++ b/lib/siade/entreprise_adapter.rb @@ -4,19 +4,9 @@ class SIADE::EntrepriseAdapter end def data_source - @data_source ||= JSON.parse(SIADE::API.entreprise(@siren), symbolize_names: true).merge(http_code: 200) - rescue RestClient::ServiceUnavailable - @data_source = {http_code: 503} - rescue RestClient::ResourceNotFound - @data_source = {http_code: 404} - rescue RestClient::InternalServerError - @data_source = {http_code: 500} - rescue => e - if e.http_code == 400 - @data_source = {http_code: 400} - else - @data_source = nil - end + @data_source ||= JSON.parse(SIADE::API.entreprise(@siren), symbolize_names: true) + rescue + @data_source = nil end def to_params @@ -29,7 +19,7 @@ class SIADE::EntrepriseAdapter params rescue - data_source + nil end def attr_to_fetch diff --git a/spec/lib/siade/api_spec.rb b/spec/lib/siade/api_spec.rb index 747da2e03..a82a3e4d7 100644 --- a/spec/lib/siade/api_spec.rb +++ b/spec/lib/siade/api_spec.rb @@ -15,9 +15,6 @@ describe SIADE::API do it 'raises RestClient::ResourceNotFound' do expect { subject }.to raise_error(RestClient::ResourceNotFound) end - - it { expect(subject.http_code).to eq status } - end context 'when siret exist' do let(:siren) { '418166096' } diff --git a/spec/lib/siade/entreprise_adapter_spec.rb b/spec/lib/siade/entreprise_adapter_spec.rb index 55f1bf597..3cfd96673 100644 --- a/spec/lib/siade/entreprise_adapter_spec.rb +++ b/spec/lib/siade/entreprise_adapter_spec.rb @@ -12,8 +12,6 @@ describe SIADE::EntrepriseAdapter do expect(subject).to be_an_instance_of(Hash) end - it { expect(described_class.new('418166096').data_source[:http_code]).to eq 200 } - context 'Attributs Entreprises' do it 'L\'entreprise contient bien un siren' do expect(subject[:siren]).to eq('418166096')