title: Handle exceptions thrown by a custom okhttp Interceptor in Kotlin Coroutines
body: <p>I'm using a custom <code>Interceptor</code> along with Retrofit client in my Android app, that throws an Exception under some specific circumstances. I'm trying to make it work using Kotlin coroutines.</p>
  
  <p>The problem is that I'm unable to handle the before mentioned error, since in the moment the exception is thrown from within the Interceptor instance, it crashes the whole app instead of being caught in the coroutine's <code>try/catch</code> statement. While I was using the Rx implementation, the exception was flawlessly propagated to the <code>onError</code> callback where I was able to handle it the way I needed. </p>
  
  <p>I guess this is somehow related to the underlying threads that are being used for the network call, please see the logs below from the place where the call is made, from the interceptor just before throwing the exception, and the stacktrace:</p>
  
  <pre><code>2019-11-04 17:17:34.515 29549-29729/com.app W/TAG: Running thread: DefaultDispatcher-worker-1
  2019-11-04 17:17:45.911 29549-29834/com.app W/TAG: Interceptor thread: OkHttp https://some.endpoint.com/...
  
  2019-11-04 17:17:45.917 29549-29834/com.app E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
      Process: com.app, PID: 29549
      com.app.IllegalStateException: Passed refresh token can\'t be used for refreshing the token.
          at com.app.net.AuthInterceptor.intercept(AuthInterceptor.kt:33)
  </code></pre>
  
  <p>What am I supposed to do in order to be able to catch and handle this exception from the Interceptor correctly? Am I missing something?</p>