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. ...

April 12, 2024 · 1 min · gmirchev90

Retrofit – Authorization & Expiring Tokens

Situation is like this: You got an AccessToken and RefreshToken (AT and RT for now on) Every API call needs to contain the AT When the AT expires you need to refresh it using your RT

May 4, 2020 · 2 min · gmirchev90