#Matt11-ratelimite

1 messages · Page 1 of 1 (latest)

abstract sequoia
#

Hi there!

fast verge
#

thank you!

#

another question

#

how can I listen for error 429?

#

I'm calling the Stripe::Subscription.update API but it returns the subscription or an error message

abstract sequoia
fast verge
#

how can I watch for 429 status?

#

rescue Stripe::RateLimitError?

abstract sequoia
#

When you code calls the Stripe API, you check the response returned by Stripe. If it's a 429, then wait for some relay and retry your call.

fast verge
#

I cannot access the response status directly

#

this is a response #<Stripe::InvalidRequestError: (Status 404) (Request req_31PEIRQUlc62xN) No such subscription: 'sub_1Kkr3OApMCw5clA3RucvxHLY'>

#

let's say res = Stripe::Subscription.update(stripe_subscription_id, { cancel_at_period_end: false }), I cannot call the res.status, res.status_code, etc

abstract sequoia
#

In general you should catch the errors Stripe return, this is explained on this page: https://stripe.com/docs/error-handling
Also the error you just shared is not about rate limits, since the code is 404 and not 429.

fast verge
#

this is the only example I was able to reproduce

abstract sequoia
#

Note that the subscription sub_1Kkr3OApMCw5clA3RucvxHLY doesn't exist, so it's expected to return a 404.

fast verge
#

I know

abstract sequoia
fast verge
#

suppose I receive a 429 and I catch the Stripe::RateLimitError. How can I access the params given to the request?
Eg: res = Stripe::Subscription.update('abcdef', { cancel_at_period_end: false }) how can I access the 'abcdef' param?

abstract sequoia
#

What programming language are you using? Ruby?

fast verge
#

Yes

abstract sequoia
fast verge
#

not a problem

#

I'll figure out

#

thanks!