Ive created an interceptor. In some cases, I want to retry the request 'n' number of time how do i do this?
class NetworkErrorHandler constructor(): Interceptor {
//Central error handling block for errors which has impact all over the app
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
var response = chain.proceed(request)
return
when (response.code) {
401 -> {
response
}
200 ->{
response
}
else -> {
var tryCount = 0
while (tryCount < 3) {
try {
response = chain.proceed(request)
tryCount++
}catch (e: java.lang.Exception){
tryCount++
}
}
response
}
}
}
}
It gives me this error:
Suppressed: java.lang.IllegalStateException: network interceptor must call proceed() exactly once
Do I have to do this here if yes, then how?