Skip to content

Commit

Permalink
feat(core): add ECONNRESET error as retriable error (#20354)
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhangi-google authored Oct 11, 2024
1 parent 59f3b3a commit c1ec100
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion google-apis-core/lib/google/apis/core/http_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,12 @@ def error(err, rethrow: false, &block)
rescue Google::Apis::Error => e
err = e
end
elsif err.is_a?(HTTPClient::TimeoutError) || err.is_a?(SocketError) || err.is_a?(HTTPClient::KeepAliveDisconnected) || err.is_a?(Errno::ECONNREFUSED) || err.is_a?(Errno::ETIMEDOUT)
elsif err.is_a?(HTTPClient::TimeoutError) ||
err.is_a?(SocketError) ||
err.is_a?(HTTPClient::KeepAliveDisconnected) ||
err.is_a?(Errno::ECONNREFUSED) ||
err.is_a?(Errno::ETIMEDOUT) ||
err.is_a?(Errno::ECONNRESET)
err = Google::Apis::TransmissionError.new(err)
end
block.call(nil, err) if block_given?
Expand Down
7 changes: 7 additions & 0 deletions google-apis-core/spec/google/apis/core/http_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,13 @@ class SecretPayload
expect { command.execute(client) }.to raise_error(Google::Apis::TransmissionError)
end

it 'should raise transmission error for broken network connection' do
stub_request(:get, 'https://www.googleapis.com/zoo/animals').to_raise(Errno::ECONNRESET)
command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
command.options.retries = 0
expect { command.execute(client) }.to raise_error(Google::Apis::TransmissionError)
end

it 'should raise rate limit error for 429 status codes' do
stub_request(:get, 'https://www.googleapis.com/zoo/animals').to_return(status: [429, ''])
command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
Expand Down

0 comments on commit c1ec100

Please sign in to comment.