RxRequester
RxRequester copied to clipboard
Add interceptors to RxRequester
Hi , I am just wanna asking about how to add different interceptors to client based on each screen have ? for example : 1-Login Screen : does not need ay custom interceptors 2-HomeScreen : It is based on token received from login screen ,so i need to add access token to header in get homepage content
How can i do this using RxRequester?
Hi Abanoub,
Thanks for your question.
Adding Interceptors is out of the scope of RxRequester. You can add any interceptors using okhttp3.Interceptor as regular , for example:
class TokenInterceptor() : Interceptor {
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
var request = chain.request()
request = request.newBuilder()
.addHeader("Authorization", "TOKEN")
.build()
return chain.proceed(request)
}
}
// Add Interceptor
val builder = OkHttpClient.Builder()
.addInterceptor(TokenInterceptor())
.build()
The library just handles Retrofit errors and other errors, BUT doesn't apply any network configurations.