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

User-friendly messages for EOFError network errors #859

Merged
merged 2 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
user-friendly messages for EOFError network errors
  • Loading branch information
elfassy committed Oct 3, 2019
commit 0c2fed71baea160918cf9028f9059e37e96f3932
8 changes: 8 additions & 0 deletions lib/stripe/stripe_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ def self.should_retry?(error, method:, num_retries:)
# Destination refused the connection, the connection was reset, or a
# variety of other connection failures. This could occur from a single
# saturated server, so retry in case it's intermittent.
return true if error.is_a?(EOFError)
return true if error.is_a?(Errno::ECONNREFUSED)
return true if error.is_a?(Errno::ECONNRESET)
return true if error.is_a?(Errno::EHOSTUNREACH)
return true if error.is_a?(Errno::ETIMEDOUT)
return true if error.is_a?(SocketError)

if error.is_a?(Stripe::StripeError)
Expand Down Expand Up @@ -296,7 +300,11 @@ def execute_request(method, path,
# The original error message is also appended onto the final exception for
# full transparency.
NETWORK_ERROR_MESSAGES_MAP = {
EOFError => ERROR_MESSAGE_CONNECTION,
Errno::ECONNREFUSED => ERROR_MESSAGE_CONNECTION,
Errno::ECONNRESET => ERROR_MESSAGE_CONNECTION,
Errno::EHOSTUNREACH => ERROR_MESSAGE_CONNECTION,
Errno::ETIMEDOUT => ERROR_MESSAGE_TIMEOUT_CONNECT,
SocketError => ERROR_MESSAGE_CONNECTION,

Net::OpenTimeout => ERROR_MESSAGE_TIMEOUT_CONNECT,
Expand Down
20 changes: 20 additions & 0 deletions test/stripe/stripe_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,26 @@ class StripeClientTest < Test::Unit::TestCase
method: :post, num_retries: 0)
end

should "retry on EOFError" do
assert StripeClient.should_retry?(EOFError.new,
method: :post, num_retries: 0)
end

should "retry on Errno::ECONNRESET" do
assert StripeClient.should_retry?(Errno::ECONNRESET.new,
method: :post, num_retries: 0)
end

should "retry on Errno::ETIMEDOUT" do
assert StripeClient.should_retry?(Errno::ETIMEDOUT.new,
method: :post, num_retries: 0)
end

should "retry on Errno::EHOSTUNREACH" do
assert StripeClient.should_retry?(Errno::EHOSTUNREACH.new,
method: :post, num_retries: 0)
end

should "retry on Net::OpenTimeout" do
assert StripeClient.should_retry?(Net::OpenTimeout.new,
method: :post, num_retries: 0)
Expand Down