The class InvalidRequestException doesn't expose stripeError.code making it difficult to handle it.
Have a look here at private static void handleAPIError()
You can see it just looking at the SDK source code, there is no other code needed. Anyway, one example case where you would need to access the error.code but you can't is when you pay with an unsupported card.
{
"error": {
"code": "card_declined",
"doc_url": "https://stripe.com/docs/error-codes/card-declined",
"message": "Your card is not supported.",
"type": "invalid_request_error"
}
}
This is the JSON response got from the backend, which is wrapped into an InvalidRequestException and so you can't access the card_declined error.
Doesn't matter.
v8.0.0
I'm not sure where to open a new issue or put this question here because it's kind of related to the same argument: shouldn't a payment with an unsupported card be returned by the server with a 402 status code (instead of a 400 as it is now) so it will be wrapped into a CardException (which exposes error.code)? Actually imho paying with an unsupported card is not an invalid request (e.g. it doesn't miss any mandatory param) so it should follow a different flow.
Please check the related iOS issue I opened here stripe/stripe-ios#1001
Hi @ema987 !
Thanks for bringing to us (and the through write up)! I've added this as task in to our internal task tracking system.
Hi @ksun-stripe ,
thank you for taking care of this! I will keep my eyes open to follow updates!
@ema987 I'll put up a PR to include StripeError.code and StripeError.declineCode in InvalidRequestException
@ema987 this will go out in the next SDK release. Can you confirm if this change is what you were looking for?
Hello @mshafrir-stripe, thank you for the update! I didn't have time to build the latest master branch but looking at the PR it looks like what I was looking for. Thank you!
Most helpful comment
@ema987 I'll put up a PR to include
StripeError.codeandStripeError.declineCodeinInvalidRequestException