api_entreprise: display better error message when SIRET is private (#3953)

Usager : meilleur message d'erreur lorsque les informations d'une entreprise ne sont pas publiques
This commit is contained in:
Pierre de La Morinerie 2019-06-12 16:03:54 +02:00 committed by GitHub
commit 14e5e2b61f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View file

@ -34,7 +34,7 @@ class ApiEntreprise::API
if response.success? if response.success?
JSON.parse(response.body, symbolize_names: true) JSON.parse(response.body, symbolize_names: true)
elsif response.code == 404 || response.code == 422 elsif response.code&.between?(401, 499)
raise RestClient::ResourceNotFound raise RestClient::ResourceNotFound
else else
raise RestClient::RequestFailed raise RestClient::RequestFailed

View file

@ -0,0 +1,6 @@
{
"errors": [
"Le SIREN ou SIRET est non diffusable"
],
"gateway_error": true
}

View file

@ -31,7 +31,17 @@ describe ApiEntreprise::API do
end end
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(:siren) { '418166096' }
let(:status) { 200 } let(:status) { 200 }
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises.json') } let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises.json') }