Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gestion de nouveaux codes d'erreur dans l'API Entreprise #10922

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/lib/api_entreprise/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def handle_response(response)
def service_unavailable?(response)
return true if response.code == 503
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

Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/files/api_entreprise/error_code_02002.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"errors": [{ "code": "02002" }]
}
3 changes: 3 additions & 0 deletions spec/fixtures/files/api_entreprise/error_code_03002.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"errors": [{ "code": "03002" }]
}
20 changes: 20 additions & 0 deletions spec/lib/api_entreprise/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@
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
let(:siren) { '111111111' }
let(:status) { 404 }
Expand Down
Loading