raise BadFormatRequest error
L'intention est de distinguer ce type d'erreur avec les erreurs serveur 5xx. Lorsque l'api est appelé par un Job, les erreurs serveur seront retry, car éphémères. Alors que les erreurs de type BadFormatRequest ou ResourceNotFound n'ont pas être retried.
This commit is contained in:
parent
f40123fee1
commit
d92a0ba8f3
2 changed files with 15 additions and 0 deletions
|
@ -17,6 +17,9 @@ class ApiEntreprise::API
|
|||
class RequestFailed < StandardError
|
||||
end
|
||||
|
||||
class BadFormatRequest < StandardError
|
||||
end
|
||||
|
||||
def self.entreprise(siren, procedure_id)
|
||||
call(ENTREPRISE_RESOURCE_NAME, siren, procedure_id)
|
||||
end
|
||||
|
@ -72,6 +75,8 @@ class ApiEntreprise::API
|
|||
JSON.parse(response.body, symbolize_names: true)
|
||||
elsif response.code&.between?(401, 499)
|
||||
raise ResourceNotFound
|
||||
elsif response.code == 400
|
||||
raise BadFormatRequest
|
||||
else
|
||||
raise RequestFailed, "HTTP Error Code: #{response.code}"
|
||||
end
|
||||
|
|
|
@ -32,6 +32,16 @@ describe ApiEntreprise::API do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when request has bad format' do
|
||||
let(:siren) { '111111111' }
|
||||
let(:status) { 400 }
|
||||
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_not_found.json') }
|
||||
|
||||
it 'raises ApiEntreprise::API::BadFormatRequest' do
|
||||
expect { subject }.to raise_error(ApiEntreprise::API::BadFormatRequest)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when siren infos are private' do
|
||||
let(:siren) { '111111111' }
|
||||
let(:status) { 403 }
|
||||
|
|
Loading…
Reference in a new issue