Skip to content
Draft
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 lib/volcano/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def self.body(response, expected_status)
def self.response_error(response)
# @type var payload: Hash[String, Object?]
payload = response.body.is_a?(Hash) ? response.body : {}
retry_after = integer_header(response.headers, 'Retry-After') if response.status == 429
retry_after = integer_header(response.headers, 'Retry-After') if [429, 503].include?(response.status)
error_type(response.status).new(
error_message(payload),
status: response.status,
Expand Down
11 changes: 7 additions & 4 deletions spec/volcano/error_mapping_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
let(:transport) { instance_double(Volcano.const_get(:GeneratedTransport)) }
let(:client) { Volcano::Client.new(anon_key: 'anon-key', _transport: transport) }

let(:retryable_statuses) { [429, 503] }

{
400 => 'Volcano::Error::ValidationError',
422 => 'Volcano::Error::ValidationError',
Expand All @@ -31,11 +33,12 @@
expect do
client.auth.sign_in(email: 'user@example.com', password: 'wrong')
end.to raise_error(Object.const_get(error_name)) { |error|
expect(error.message).to eq('contract failure')
expect(error.status).to eq(status)
expect(error.code).to eq('contract_code')
expect(error.retry_after).to eq(status == 429 ? 17 : nil)
expect(error).to have_attributes(
message: 'contract failure', status: status, code: 'contract_code',
retry_after: retryable_statuses.include?(status) ? 17 : nil
)
}
expect(transport).to have_received(:auth_signin).once
end
end

Expand Down
Loading