diff --git a/app/lib/api_entreprise/api.rb b/app/lib/api_entreprise/api.rb index a84dd8c36..f90abd6e9 100644 --- a/app/lib/api_entreprise/api.rb +++ b/app/lib/api_entreprise/api.rb @@ -34,7 +34,7 @@ class ApiEntreprise::API if response.success? JSON.parse(response.body, symbolize_names: true) - elsif response.code == 404 || response.code == 422 + elsif response.code&.between?(401, 499) raise RestClient::ResourceNotFound else raise RestClient::RequestFailed diff --git a/spec/fixtures/files/api_entreprise/entreprises_private.json b/spec/fixtures/files/api_entreprise/entreprises_private.json new file mode 100644 index 000000000..0b77b10ee --- /dev/null +++ b/spec/fixtures/files/api_entreprise/entreprises_private.json @@ -0,0 +1,6 @@ +{ + "errors": [ + "Le SIREN ou SIRET est non diffusable" + ], + "gateway_error": true +} diff --git a/spec/lib/api_entreprise/api_spec.rb b/spec/lib/api_entreprise/api_spec.rb index f2beb720f..abd7c07c2 100644 --- a/spec/lib/api_entreprise/api_spec.rb +++ b/spec/lib/api_entreprise/api_spec.rb @@ -31,7 +31,17 @@ describe ApiEntreprise::API do end end - context 'when siret exist' do + context 'when siren infos are private' do + let(:siren) { '111111111' } + let(:status) { 403 } + let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_private.json') } + + it 'raises RestClient::ResourceNotFound' do + expect { subject }.to raise_error(RestClient::ResourceNotFound) + end + end + + context 'when siren exist' do let(:siren) { '418166096' } let(:status) { 200 } let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises.json') }