Skip to content

⚠️ Use HTTP status code in V2 errors#2131

Merged
mbroshi-stripe merged 3 commits intomasterfrom
mbroshi/v2-error-handling
Mar 24, 2026
Merged

⚠️ Use HTTP status code in V2 errors#2131
mbroshi-stripe merged 3 commits intomasterfrom
mbroshi/v2-error-handling

Conversation

@mbroshi-stripe
Copy link
Copy Markdown
Contributor

@mbroshi-stripe mbroshi-stripe commented Dec 18, 2025

Why?

We did an audit of V2 error-handling across our SDKs, and realized that in V2 APIs, Java users do not get typed exceptions based on HTTP Status Code like they do when calling a V1 API. E.g. a 429 response code from Stripe in V1 throws a RateLimitException, but against a V2 API, it will throw a more generic ApiException. Also, as part of our audit, we decided that it makes more sense to make RateLimitException extend StripeException rather than ApiException (since it does not come explicitly from the Stripe API). The reason it extends ApiException is that we anticipated that it would be in the API (it was briefly in Private Preview), which was a change we made in #2046.

What?

  • Refactors V1 and V2 code paths so they delegate to the same HTTP Status Code based logic
  • RateLimitException now extends StripeException rather than ApiException
  • Tests for all the edge cases of the new behavior

Changelog

  • ⚠️ RateLimitException now extends StripeException rather than ApiException
  • ⚠️ Non-200 status codes from V2 endpoints will throw a StripeException (e.g. RateLimitException, InvalidRequestException, etc.) like in V1 instead of a generic ApiException

@mbroshi-stripe mbroshi-stripe requested a review from a team as a code owner December 18, 2025 21:47
@mbroshi-stripe mbroshi-stripe requested review from prathmesh-stripe and removed request for a team December 18, 2025 21:47
@mbroshi-stripe mbroshi-stripe changed the title Use HTTP status code in V2 errors ⚠️ Use HTTP status code in V2 errors Dec 18, 2025
Comment thread src/main/java/com/stripe/exception/RateLimitException.java
@mbroshi-stripe mbroshi-stripe enabled auto-merge (squash) March 24, 2026 23:27
@mbroshi-stripe mbroshi-stripe merged commit c1e7f1b into master Mar 24, 2026
16 checks passed
@mbroshi-stripe mbroshi-stripe deleted the mbroshi/v2-error-handling branch March 24, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants