From d3e69029786febff255380831b96be39906b8c51 Mon Sep 17 00:00:00 2001 From: Ted Kim Date: Sat, 14 Nov 2026 14:26:07 -0500 Subject: [PATCH] fix(transport): preserve retry delay on service unavailable responses --- lib/volcano/transport.rb | 2 +- spec/volcano/error_mapping_spec.rb | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/volcano/transport.rb b/lib/volcano/transport.rb index bedcbb71..69f63928 100644 --- a/lib/volcano/transport.rb +++ b/lib/volcano/transport.rb @@ -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, diff --git a/spec/volcano/error_mapping_spec.rb b/spec/volcano/error_mapping_spec.rb index b329ff8d..4ae3f970 100644 --- a/spec/volcano/error_mapping_spec.rb +++ b/spec/volcano/error_mapping_spec.rb @@ -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', @@ -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