Skip to content

Commit f030720

Browse files
committed
fix(onramp): add trace logging to Coinbase OnRamp error paths
Log response bodies and error details at all failure points in CoinbaseOnRampController for easier debugging of HTTP and JWT errors. Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 92333bb commit f030720

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

apps/flipcash/shared/onramp/coinbase/src/main/kotlin/com/flipcash/app/onramp/CoinbaseOnRampController.kt

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import com.getcode.vendor.Base58
3030
import com.flipcash.app.core.AppRoute
3131
import com.flipcash.app.onramp.internal.CoinbaseOnRampWebError
3232
import com.getcode.utils.ErrorUtils
33+
import com.getcode.utils.trace
3334
import dagger.hilt.android.scopes.ActivityRetainedScoped
3435
import kotlinx.coroutines.flow.MutableSharedFlow
3536
import kotlinx.coroutines.flow.MutableStateFlow
@@ -154,7 +155,15 @@ class CoinbaseOnRampController @Inject constructor(
154155
.onSuccess { swapId ->
155156
_state.update { CoinbaseOnRampState.Completed(swapId, current.token, current.amount) }
156157
}
157-
.onFailure {
158+
.onFailure { error ->
159+
trace(
160+
message = "Payment processing failed",
161+
tag = "OnRamp",
162+
error = error,
163+
) {
164+
"orderId" to current.orderId
165+
"errorType" to error::class.simpleName.orEmpty()
166+
}
158167
reset()
159168
}
160169
}
@@ -262,6 +271,18 @@ class CoinbaseOnRampController @Inject constructor(
262271
url = "${onRampApiEndpoint.baseUrl}$path",
263272
jwt = "Bearer $jwt",
264273
)
274+
}.onFailure { error ->
275+
if (error is HttpException) {
276+
val errorBody = error.response()?.errorBody()?.string()
277+
trace(
278+
message = "Coinbase order lookup HTTP ${error.code()}",
279+
tag = "OnRamp",
280+
error = error,
281+
) {
282+
"orderId" to orderId
283+
"responseBody" to errorBody.orEmpty()
284+
}
285+
}
265286
}.map { it.order }
266287
}
267288
)
@@ -287,6 +308,14 @@ class CoinbaseOnRampController @Inject constructor(
287308
).fold(
288309
onSuccess = { call(it) },
289310
onFailure = { error ->
311+
trace(
312+
message = "JWT request failed",
313+
tag = "OnRamp",
314+
error = error,
315+
) {
316+
"endpoint" to "$method $host$path"
317+
"errorType" to error::class.simpleName.orEmpty()
318+
}
290319
when (error) {
291320
is GetJwtError.EmailVerificationRequired -> Result.failure(
292321
OnRampAuthError.VerificationRequired(
@@ -347,6 +376,11 @@ class CoinbaseOnRampController @Inject constructor(
347376
onFailure = { error ->
348377
if (error is HttpException) {
349378
val errorBody = error.response()?.errorBody()?.string()
379+
trace(
380+
message = "Coinbase OnRamp HTTP ${error.code()}",
381+
tag = "OnRamp",
382+
error = error,
383+
) { "responseBody" to errorBody.orEmpty() }
350384
if (errorBody != null) {
351385
val coinbaseError = runCatching { json.decodeFromString<CoinbaseOnRampApiError>(errorBody) }
352386
.getOrNull()

0 commit comments

Comments
 (0)