我创建了一个拦截器,有些情况下,我想重试请求'n'次,请问该如何实现?
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
}
}
}
}
我收到了这个错误:
Suppressed: java.lang.IllegalStateException: network interceptor must call proceed() exactly once
我需要在这里做吗?如果是的话,应该怎么做呢?