Skip to content

Commit

Permalink
user-friendly messages for EOFError network errors
Browse files Browse the repository at this point in the history
  • Loading branch information
elfassy committed Oct 3, 2019
1 parent 27718e0 commit d919eff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/stripe/stripe_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ 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::ECONNRESET => ERROR_MESSAGE_CONNECTION,
Errno::ETIMEDOUT => ERROR_MESSAGE_TIMEOUT_CONNECT,
Errno::EHOSTUNREACH => ERROR_MESSAGE_CONNECTION,
Errno::ECONNREFUSED => ERROR_MESSAGE_CONNECTION,
SocketError => ERROR_MESSAGE_CONNECTION,

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

0 comments on commit d919eff

Please sign in to comment.