ClassCastException: kotlin.Result$Failure cannot be cast to retrofit2.Response
Opened this issue · 1 comments
Jeff11 commented
Is there a way to handle exceptions from Retrofit? We often get these ClassCastExceptions in the await()
call.
interface Api {
@GET("api/config")
fun getConfigAsync(): Deferred<Response<String>>
}
launch { // UI
try {
val response = api.getConfigAsync().await()
doSomething(response)
} catch (e: Exception) {
Timber.e(e)
}
}
Exception: java.lang.ClassCastException: kotlin.Result$Failure cannot be cast to retrofit2.Response
at com.example.Setup$loadConfig$1.invokeSuspend(Setup.kt:385)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:285)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$getSchedulerName$p(CoroutineScheduler.kt:60)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742)
mikhailmelnik commented
Same here. Have number of similar stacktraces from every place I use coroutines in but it is impossible to find out what the root cause was. I can only guess it might be a network issue.