Here's the case I'm trying to handle,
- If a request is executed, and the response indicates the auth token is expired,
- send a refresh token request
- if the refresh token request succeeds, retry the original request
This should be transparent to the calling Activity, Fragment... etc. From the caller's point of view, it's one request, and one response.
I've achieved this flow before when using OkHttpClient directly, but I don't know how to achieve this in Retrofit.
Maybe something related to this open issue about a ResponseInterceptor?
If there's no straight-forward way to achieve this in retrofit, what would be the best way to implement it? A base listener class?
I'm using RoboSpice with Retrofit as well, if it can be helpful in such case.
OkHttp
as yourHTTP client
andRetrofit
>=1.9
then you can use the newInterceptor
. See my answer here for an example. Otherwise, we will need to wait forRetrofit 2.0
to be released. – Lyricist