Retrofit Handling Token Expiration
Solution 1:
Retrofit is made to help YOU handle the requests you need. It doesn't handle token expiration. This means, that you need to handle that yourself. For example, in your request error handling, you can check for 401 error Unauthorized (this is usually the error a server sends when a token expires). When this occurs, hold the failed request and send another request for a new token. When the new request is successfully completed, you will have your token refreshed and you can retry the initial failed request with the newly fetched token.
Solution 2:
i think that u can use an OkHttp Interceptor to catch 401 Unauthorized for any request and than refresh your token and retry your request.
https://futurestud.io/tutorials/retrofit-2-catch-server-errors-globally-with-response-interceptor
Global Error Handler: OkHttp Interceptor
Post a Comment for "Retrofit Handling Token Expiration"