stripe 5.4.1 → 5.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e5f20e4c43413ce6119c1b2ba7c064d2cdbec25abfe76a3cf90e52a5b9c0ec4
4
- data.tar.gz: 6deab0e7d3057f7c38fa5c629fda1d079a4c99c3d6ef09cc495a589a63649815
3
+ metadata.gz: 04bf14074bb94dbb41edf733c9240f770026a9e51647359d4d1d55820c1f3c46
4
+ data.tar.gz: e5a8433b4284faf095da5ad4ebd102127b005a52b56b7651dadfa579a06188f1
5
5
  SHA512:
6
- metadata.gz: cc079329105fdc6498addef346923e48e52ac9f77d02d605eacd8b50fe302918db0405b4634f941bc8423e29c72227d84531684c82b436c4c71a8a9244c7fd53
7
- data.tar.gz: b8548a9fd9d0b004af8d18994ea550072dc5df17b66a9635c394a9cb405f3145e4e25ab06030945e8ab79758891ce9636bdf3449082a371188ea022c504eee5f
6
+ metadata.gz: e905a1f7fa40887d5c8bd78c428f1d377b42ead6586cf147f6334fafc6264d81ccbdb504e6ef2c8da3e473f40ad18b275f372cc70eea147435252d813ac948b8
7
+ data.tar.gz: 3d03fb7104356a787b85287455e74157761e92b159db33414685af565fd99e7ff596e9cd1f4ce7dd0e00f44e2c342618fc65f52ad91ed7ccedabd42db6d990c4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.5.0 - 2019-10-03
4
+ * [#859](https://github.com/stripe/stripe-ruby/pull/859) User-friendly messages and retries for `EOFError`, `Errno::ECONNRESET`, `Errno::ETIMEDOUT`, and `Errno::EHOSTUNREACH` network errors
5
+
3
6
  ## 5.4.1 - 2019-10-01
4
7
  * [#858](https://github.com/stripe/stripe-ruby/pull/858) Drop Timecop dependency
5
8
 
data/Gemfile CHANGED
@@ -11,7 +11,6 @@ group :development do
11
11
  gem "rake"
12
12
  gem "shoulda-context"
13
13
  gem "test-unit"
14
- gem "timecop"
15
14
  gem "webmock"
16
15
 
17
16
  # Rubocop changes pretty quickly: new cops get added and old cops change
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.4.1
1
+ 5.5.0
@@ -81,17 +81,17 @@ module Stripe
81
81
  def self.should_retry?(error, method:, num_retries:)
82
82
  return false if num_retries >= Stripe.max_network_retries
83
83
 
84
- # Retry on timeout-related problems (either on open or read).
85
- return true if error.is_a?(Net::OpenTimeout)
86
- return true if error.is_a?(Net::ReadTimeout)
87
-
88
- # Destination refused the connection, the connection was reset, or a
89
- # variety of other connection failures. This could occur from a single
90
- # saturated server, so retry in case it's intermittent.
91
- return true if error.is_a?(Errno::ECONNREFUSED)
92
- return true if error.is_a?(SocketError)
93
-
94
- if error.is_a?(Stripe::StripeError)
84
+ case error
85
+ when Net::OpenTimeout, Net::ReadTimeout
86
+ # Retry on timeout-related problems (either on open or read).
87
+ true
88
+ when EOFError, Errno::ECONNREFUSED, Errno::ECONNRESET,
89
+ Errno::EHOSTUNREACH, Errno::ETIMEDOUT, SocketError
90
+ # Destination refused the connection, the connection was reset, or a
91
+ # variety of other connection failures. This could occur from a single
92
+ # saturated server, so retry in case it's intermittent.
93
+ true
94
+ when Stripe::StripeError
95
95
  # The API may ask us not to retry (e.g. if doing so would be a no-op),
96
96
  # or advise us to retry (e.g. in cases of lock timeouts). Defer to
97
97
  # those instructions if given.
@@ -119,10 +119,10 @@ module Stripe
119
119
  return true if error.http_status == 500 && method != :post
120
120
 
121
121
  # 503 Service Unavailable
122
- return true if error.http_status == 503
122
+ error.http_status == 503
123
+ else
124
+ false
123
125
  end
124
-
125
- false
126
126
  end
127
127
 
128
128
  def self.sleep_time(num_retries)
@@ -296,7 +296,11 @@ module Stripe
296
296
  # The original error message is also appended onto the final exception for
297
297
  # full transparency.
298
298
  NETWORK_ERROR_MESSAGES_MAP = {
299
+ EOFError => ERROR_MESSAGE_CONNECTION,
299
300
  Errno::ECONNREFUSED => ERROR_MESSAGE_CONNECTION,
301
+ Errno::ECONNRESET => ERROR_MESSAGE_CONNECTION,
302
+ Errno::EHOSTUNREACH => ERROR_MESSAGE_CONNECTION,
303
+ Errno::ETIMEDOUT => ERROR_MESSAGE_TIMEOUT_CONNECT,
300
304
  SocketError => ERROR_MESSAGE_CONNECTION,
301
305
 
302
306
  Net::OpenTimeout => ERROR_MESSAGE_TIMEOUT_CONNECT,
data/lib/stripe/util.rb CHANGED
@@ -178,9 +178,8 @@ module Stripe
178
178
  # to calculate an elapsed duration.
179
179
  #
180
180
  # Shortcut for getting monotonic time, mostly for purposes of line length
181
- # and stubbing (Timecop doesn't freeze the monotonic clock). Returns time
182
- # in seconds since the event used for monotonic reference purposes by the
183
- # platform (e.g. system boot time).
181
+ # and test stubbing. Returns time in seconds since the event used for
182
+ # monotonic reference purposes by the platform (e.g. system boot time).
184
183
  def self.monotonic_time
185
184
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
186
185
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stripe
4
- VERSION = "5.4.1"
4
+ VERSION = "5.5.0"
5
5
  end
@@ -172,6 +172,26 @@ module Stripe
172
172
  method: :post, num_retries: 0)
173
173
  end
174
174
 
175
+ should "retry on EOFError" do
176
+ assert StripeClient.should_retry?(EOFError.new,
177
+ method: :post, num_retries: 0)
178
+ end
179
+
180
+ should "retry on Errno::ECONNRESET" do
181
+ assert StripeClient.should_retry?(Errno::ECONNRESET.new,
182
+ method: :post, num_retries: 0)
183
+ end
184
+
185
+ should "retry on Errno::ETIMEDOUT" do
186
+ assert StripeClient.should_retry?(Errno::ETIMEDOUT.new,
187
+ method: :post, num_retries: 0)
188
+ end
189
+
190
+ should "retry on Errno::EHOSTUNREACH" do
191
+ assert StripeClient.should_retry?(Errno::EHOSTUNREACH.new,
192
+ method: :post, num_retries: 0)
193
+ end
194
+
175
195
  should "retry on Net::OpenTimeout" do
176
196
  assert StripeClient.should_retry?(Net::OpenTimeout.new,
177
197
  method: :post, num_retries: 0)
@@ -316,11 +336,11 @@ module Stripe
316
336
 
317
337
  context "logging" do
318
338
  setup do
319
- # Freeze time for the purposes of the `elapsed` parameter that we emit
320
- # for responses. Mocha's `anything` parameter can't match inside of a
321
- # hash and is therefore not useful for this purpose, and Timecop
322
- # doesn't freeze monotonic time. If we switch over to rspec-mocks at
323
- # some point, we can probably remove Timecop from the project.
339
+ # Freeze time for the purposes of the `elapsed` parameter that we
340
+ # emit for responses. Mocha's `anything` parameter can't match inside
341
+ # of a hash and is therefore not useful for this purpose. If we
342
+ # switch over to rspec-mocks at some point, we can probably remove
343
+ # this.
324
344
  Util.stubs(:monotonic_time).returns(0.0)
325
345
  end
326
346
 
data/test/test_helper.rb CHANGED
@@ -8,7 +8,6 @@ require "test/unit"
8
8
  require "mocha/setup"
9
9
  require "stringio"
10
10
  require "shoulda/context"
11
- require "timecop"
12
11
  require "webmock/test_unit"
13
12
 
14
13
  PROJECT_ROOT = ::File.expand_path("../", __dir__)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.4.1
4
+ version: 5.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-01 00:00:00.000000000 Z
11
+ date: 2019-10-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Stripe is the easiest way to accept payments online. See https://stripe.com
14
14
  for details.
@@ -246,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  - !ruby/object:Gem::Version
247
247
  version: '0'
248
248
  requirements: []
249
- rubygems_version: 3.0.6
249
+ rubygems_version: 3.0.3
250
250
  signing_key:
251
251
  specification_version: 4
252
252
  summary: Ruby bindings for the Stripe API