Log errorCode when a stripe request fails.

This commit is contained in:
Greyson Parrelli 2021-11-24 15:33:13 -05:00
parent 5b2ca6a1d3
commit 89cbfd3299

View file

@ -128,7 +128,19 @@ class StripeApi(
if (response.isSuccessful) {
return response
} else {
throw IOException("postForm failure: ${response.code()}")
throw IOException("postForm failed with code: ${response.code()}. errorCode: ${parseErrorCode(response.body()?.string())}")
}
}
private fun parseErrorCode(body: String?): String? {
if (body == null) {
return "No body."
}
return try {
JSONObject(body).getJSONObject("error").getString("code")
} catch (e: Exception) {
"Unable to parse error code."
}
}