【发布时间】:2021-11-02 21:07:08
【问题描述】:
我创建了一个拦截器。在某些情况下,我想重试请求“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
如果是,我必须在这里做吗,然后怎么做?
【问题讨论】:
标签: android retrofit retrofit2 okhttp interceptor