Throwing anything other than IOException in the OkHttp interceptor will crash your app

One thing to note, maybe you don’t know about it, is that OkHttp interceptors work with IOException. So if you decide to implement some kind of a retry mechanism – to refresh a token when you get a forbidden response code, to retry a request, or something else, keep in mind that if you throw anything different than IOException or a subclass of it, like InvalidStateException, your app will crash and the exception will not even reach the try-catch block of your code.

The reason for it can be found here -> https://github.com/square/retrofit/issues/3505

Android Oauth2 token refresh mechanism – OkHttp vs RxJava layering

The RxJava approach

I am currently working on an app where the devs before me took this strange decision in regard to the refresh token mechanism – have a single entry point of the app which is called every time whenever you need to have a fresh token. What I mean is this:

Continue reading “Android Oauth2 token refresh mechanism – OkHttp vs RxJava layering”