'Android Working with Interceptors and Coroutines
I need to implement the following mechanism and need guidance on the best approach to achieve it:
I have an Android application that uses retrofit with coroutines, and MVVM style.
I want to add an interceptor to achieve the following logic:
If I receive a specific error code -> ask user for some info -> re-send the request with user info appended -> resume the flow...
I could achieve the following by launching a dialog or a bottom sheet with a callback within the interceptor, but this will require adding callbacks everywhere...
I need something more generic:
Whenever I receive this specific error code on my application (on any request) -> ask the user for some info -> repeat the request with user info appended -> resume activity/fragment logic.
Solution 1:[1]
Interceptors don't have access to UI. You can create a custom CallAdapter, Call and Callback to handle specific responses and process them as you wish.
This article suggests one way of doing that.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | zen_of_kermit |
