我正在采用RequestAdapter
并将RequestRetrier
刷新令牌行为自动添加到我的请求中。重试的问题无限期地发生而不受控制。我有这个代码:
class AuthHandler: RequestAdapter, RequestRetrier {
func adapt(_ urlRequest: URLRequest) throws -> URLRequest {
return urlRequest
}
public func should(_ manager: SessionManager, retry request: Request, with error: Error, completion: @escaping RequestRetryCompletion) {
if let response = request.task?.response as? HTTPURLResponse, response.statusCode == 401 {
_ = Credential.current.renew({ (credential, error) in
completion(true, 0.0) /// Retry request
})
} else {
completion(false, 0.0) // Don't retry
}
}
}
失败后如何只重试一次请求?
我试过这个:
request.retryCount = 1
但不起作用......有什么想法吗?
谢谢!