stripe / stripe-java

Java library for the Stripe API.
https://stripe.com
MIT License
806 stars 357 forks source link

stripeClient throw JsonSyntaxException instead of StripeException #1868

Open julienmweb opened 2 weeks ago

julienmweb commented 2 weeks ago

Describe the bug

Hi After upgrading the com.stripe:stripe-java dependency from version 26.9.0 to 26.11.0, a test in our project fails:

The test expects stripeClient to throw a StripeException, but instead, a com.google.gson.JsonSyntaxException is thrown. It looks like the JsonSyntaxException is thrown directly instead of being encapsulated within a StripeException like in the previous version

To Reproduce

Create a test: Configure WireMock to return an invalid JSON response when the stripeClient do a call a JsonSyntaxException should be thrown

java.lang.AssertionError: Expecting actual throwable to be an instance of: com.stripe.exception.StripeException but was: com.google.gson.JsonSyntaxException: Expected a com.google.gson.JsonObject but was com.google.gson.JsonPrimitive; at path $ at com.google.gson.internal.bind.TypeAdapters$34$1.read(TypeAdapters.java:1152) at com.google.gson.Gson.fromJson(Gson.java:1361) at com.google.gson.Gson.fromJson(Gson.java:1262) ...(93 remaining lines not displayed - this can be changed with Assertions.setMaxStackTraceElementsDisplayed)

Expected behavior

stripeClient should throw a StripeException

Code snippets

No response

OS

linux

Java version

21

stripe-java version

v26.11.0

API version

2024-06-20

Additional context

No response

ramya-stripe commented 1 week ago

Thanks for reporting @julienmweb We will add this to our backlog