Log errorCode when a stripe request fails.
This commit is contained in:
parent
5b2ca6a1d3
commit
89cbfd3299
1 changed files with 13 additions and 1 deletions
|
@ -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."
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue