I'm adopting RequestAdapter
and RequestRetrier
to add refresh token behavior automatically to my request.
The problems that retry occurs indefinitely without control.
I have this code:
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
}
}
}
How can I do the request retry only once after fails?
I tried this:
request.retryCount = 1
but doesn't works... Any idea?
Thanks!