From 71ff31e91f4ab4c7b9ddd437757c46a3a413c0a7 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Tue, 10 Jan 2023 15:03:15 -0400 Subject: [PATCH] Fix Stripe json body error handling. --- .../src/main/java/org/signal/donations/StripeApi.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/donations/lib/src/main/java/org/signal/donations/StripeApi.kt b/donations/lib/src/main/java/org/signal/donations/StripeApi.kt index 8abf56870..8194ac612 100644 --- a/donations/lib/src/main/java/org/signal/donations/StripeApi.kt +++ b/donations/lib/src/main/java/org/signal/donations/StripeApi.kt @@ -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)