mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-06-02 00:00:35 -04:00
Retry requests on a 429 that's a lock timeout (#841)
Tweaks the retry logic so that 429s which have the special status code lock_timeout are retried automatically. Similar to what was recently implemented in Go: stripe/stripe-go#935
This commit is contained in:
parent
82b5e510b9
commit
3e21fa977a
@ -88,6 +88,16 @@ module Stripe
|
||||
# 409 Conflict
|
||||
return true if error.http_status == 409
|
||||
|
||||
# 429 Too Many Requests
|
||||
#
|
||||
# There are a few different problems that can lead to a 429. The most
|
||||
# common is rate limiting, on which we *don't* want to retry because
|
||||
# that'd likely contribute to more contention problems. However, some
|
||||
# 429s are lock timeouts, which is when a request conflicted with
|
||||
# another request or an internal process on some particular object.
|
||||
# These 429s are safe to retry.
|
||||
return true if error.http_status == 429 && error.code == "lock_timeout"
|
||||
|
||||
# 500 Internal Server Error
|
||||
#
|
||||
# We only bother retrying these for non-POST requests. POSTs end up
|
||||
|
@ -122,6 +122,12 @@ module Stripe
|
||||
method: :post, num_retries: 0)
|
||||
end
|
||||
|
||||
should "retry on a 429 Too Many Requests when lock timeout" do
|
||||
assert StripeClient.should_retry?(Stripe::StripeError.new(http_status: 429,
|
||||
code: "lock_timeout"),
|
||||
method: :post, num_retries: 0)
|
||||
end
|
||||
|
||||
should "retry on a 500 Internal Server Error when non-POST" do
|
||||
assert StripeClient.should_retry?(Stripe::StripeError.new(http_status: 500),
|
||||
method: :get, num_retries: 0)
|
||||
@ -142,6 +148,12 @@ module Stripe
|
||||
method: :post, num_retries: 0)
|
||||
end
|
||||
|
||||
should "not retry on a 429 Too Many Requests when not lock timeout" do
|
||||
refute StripeClient.should_retry?(Stripe::StripeError.new(http_status: 429,
|
||||
code: "rate_limited"),
|
||||
method: :post, num_retries: 0)
|
||||
end
|
||||
|
||||
should "not retry on a 500 Internal Server Error when POST" do
|
||||
refute StripeClient.should_retry?(Stripe::StripeError.new(http_status: 500),
|
||||
method: :post, num_retries: 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user