If you want here it is :slightly_smiling_face: But...
# coroutines
t
If you want here it is đŸ™‚ But to be clear I can trigger the
Fatal Exception: java.net.NoRouteToHostException: No route to host
at will, 99,99% it’s catched and once in a while it’s not.
Copy code
suspend fun Call.await(): Response {
        return suspendCancellableCoroutine { continuation ->
            enqueue(object : Callback {
                override fun onResponse(call: Call, response: Response) {
                    continuation.resume(response)
                }

                override fun onFailure(call: Call, e: IOException) {
                    // Don't bother with resuming the continuation if it is already cancelled.
                    if (continuation.isCancelled) {
                        return
                    }
                    continuation.resumeWithException(e)
                }
            })
            continuation.invokeOnCancellation {
                try {
                    cancel()
                } catch (ignore: Throwable) {
                }
            }
        }
    }

    /* See <https://github.com/square/okhttp/issues/3477> */
    private class OkHttpExceptionInterceptor : Interceptor {

        @Throws(IOException::class)
        override fun intercept(chain: Interceptor.Chain): Response {
            try {
                return chain.proceed(chain.request())
            } catch (e: Throwable) {
                if (e is IOException) {
                    throw e
                } else {
                    throw IOException(e)
                }
            }
        }
    }