api_entreprise: display better error message when SIRET is private

Previously we blamed the network.

Now we say that the entreprise infos cannot be retrieved. Which is not
ideal, but better.
This commit is contained in:
Pierre de La Morinerie 2019-06-12 09:39:49 +00:00
parent 8c7d7f2eed
commit 55c9dfc001
3 changed files with 18 additions and 2 deletions

View file

@ -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

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
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') }