Fix Stripe json body error handling.

main
Alex Hart 2023-01-10 15:03:15 -04:00
rodzic aa9a530e59
commit 71ff31e91f
1 zmienionych plików z 6 dodań i 4 usunięć

Wyświetl plik

@ -131,11 +131,12 @@ class StripeApi(
fun getSetupIntent(stripeIntentAccessor: StripeIntentAccessor): StripeSetupIntent {
return when (stripeIntentAccessor.objectType) {
StripeIntentAccessor.ObjectType.SETUP_INTENT -> get("setup_intents/${stripeIntentAccessor.intentId}?client_secret=${stripeIntentAccessor.intentClientSecret}").use {
val body = it.body()?.string()
try {
objectMapper.readValue(it.body()!!.string())
objectMapper.readValue(body!!)
} catch (e: InvalidDefinitionException) {
Log.w(TAG, "Failed to parse JSON for StripeSetupIntent.")
ResponseFieldLogger.logFields(objectMapper, it.body()?.string())
ResponseFieldLogger.logFields(objectMapper, body)
throw StripeError.FailedToParseSetupIntentResponseError(e)
} catch (e: Exception) {
Log.w(TAG, "Failed to read value from JSON.", e, true)
@ -152,11 +153,12 @@ class StripeApi(
fun getPaymentIntent(stripeIntentAccessor: StripeIntentAccessor): StripePaymentIntent {
return when (stripeIntentAccessor.objectType) {
StripeIntentAccessor.ObjectType.PAYMENT_INTENT -> get("payment_intents/${stripeIntentAccessor.intentId}?client_secret=${stripeIntentAccessor.intentClientSecret}").use {
val body = it.body()?.string()
try {
objectMapper.readValue(it.body()!!.string())
objectMapper.readValue(body!!)
} catch (e: InvalidDefinitionException) {
Log.w(TAG, "Failed to parse JSON for StripePaymentIntent.")
ResponseFieldLogger.logFields(objectMapper, it.body()?.string())
ResponseFieldLogger.logFields(objectMapper, body)
throw StripeError.FailedToParsePaymentIntentResponseError(e)
} catch (e: Exception) {
Log.w(TAG, "Failed to read value from JSON.", e, true)