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:
commit
14e5e2b61f
3 changed files with 18 additions and 2 deletions
|
@ -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
|
||||||
|
|
6
spec/fixtures/files/api_entreprise/entreprises_private.json
vendored
Normal file
6
spec/fixtures/files/api_entreprise/entreprises_private.json
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"errors": [
|
||||||
|
"Le SIREN ou SIRET est non diffusable"
|
||||||
|
],
|
||||||
|
"gateway_error": true
|
||||||
|
}
|
|
@ -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') }
|
||||||
|
|
Loading…
Reference in a new issue