Retrofit 2: Catch connection timeout exception

后端 未结 7 1293
执念已碎
执念已碎 2020-11-27 03:26

I have the following setup:

final OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setReadTimeout(5, TimeUnit.SECONDS);
okHttpClient.setConnectTi         


        
7条回答
  •  不知归路
    2020-11-27 04:24

    In case someone come here with Kotlin/Coroutines facing the same issue, add an error handler to your coroutines scope:

    CoroutineScope(Dispatchers.IO).launch(handler) {
    

    while the handler by itself looks like:

    val handler = CoroutineExceptionHandler { _, exception ->
        Log.t("Network", "Caught $exception")
    }
    

提交回复
热议问题