Merge pull request #10922 from demarches-simplifiees/fix_10921
Gestion de nouveaux codes d'erreur dans l'API Entreprise
This commit is contained in:
commit
8266f7ff6c
4 changed files with 27 additions and 1 deletions
|
@ -141,7 +141,7 @@ class APIEntreprise::API
|
||||||
def service_unavailable?(response)
|
def service_unavailable?(response)
|
||||||
return true if response.code == 503
|
return true if response.code == 503
|
||||||
if response.code == 502 || response.code == 504
|
if response.code == 502 || response.code == 504
|
||||||
parse_response_errors(response).any? { _1.is_a?(Hash) && ["01000", "01001", "01002"].include?(_1[:code]) }
|
parse_response_errors(response).any? { _1.is_a?(Hash) && ["01000", "01001", "01002", "02002", "03002"].include?(_1[:code]) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
3
spec/fixtures/files/api_entreprise/error_code_02002.json
vendored
Normal file
3
spec/fixtures/files/api_entreprise/error_code_02002.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"errors": [{ "code": "02002" }]
|
||||||
|
}
|
3
spec/fixtures/files/api_entreprise/error_code_03002.json
vendored
Normal file
3
spec/fixtures/files/api_entreprise/error_code_03002.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"errors": [{ "code": "03002" }]
|
||||||
|
}
|
|
@ -54,6 +54,26 @@ describe APIEntreprise::API do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when the service reponds with 02002 code' do
|
||||||
|
let(:siren) { '111111111' }
|
||||||
|
let(:status) { 504 }
|
||||||
|
let(:body) { Rails.root.join('spec/fixtures/files/api_entreprise/error_code_02002.json').read }
|
||||||
|
|
||||||
|
it 'raises APIEntreprise::API::Error::RequestFailed' do
|
||||||
|
expect { subject }.to raise_error(APIEntreprise::API::Error::ServiceUnavailable)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the service reponds with 03002 code' do
|
||||||
|
let(:siren) { '111111111' }
|
||||||
|
let(:status) { 504 }
|
||||||
|
let(:body) { Rails.root.join('spec/fixtures/files/api_entreprise/error_code_03002.json').read }
|
||||||
|
|
||||||
|
it 'raises APIEntreprise::API::Error::RequestFailed' do
|
||||||
|
expect { subject }.to raise_error(APIEntreprise::API::Error::ServiceUnavailable)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when siren does not exist' do
|
context 'when siren does not exist' do
|
||||||
let(:siren) { '111111111' }
|
let(:siren) { '111111111' }
|
||||||
let(:status) { 404 }
|
let(:status) { 404 }
|
||||||
|
|
Loading…
Add table
Reference in a new issue