0

I am using retrofit for my http calls in an android app. Any of the calls to server can return a 401 code in any moment if the session is expired. So I need a generic mechanism to detect that code in any call, do a new login request to server and when I have the response, retry the original petition. I want to centralize that login in one method to avoid repiting the retry login in all my calls.

I think I should do that with an Interceptor. My idea is:

Create an Interceptor used by all my calls to server. In that interceptor, look for the response code. If response code is 401, do a login request and after that the original request again. And when the process finishes, interceptor has to return the response from the last request, the original one.

The problem is that I dont know how can I make new requests in the interceptor method intercept(Interceptor.Chain chain). I cant find any example to do that.

0 Answers0