繁体   English   中英

Alamofire 4.0 RequestRetrier不应该被调用(_,retry,with,completion)

[英]Alamofire 4.0 RequestRetrier should(_,retry,with,completion) not being called

我正在使用Alamofire 4.0的RequestRetrier来控制对过期访问令牌的请求的重试。 我在这里关注文档。

我的实现与文档OAuth2Handler的示例非常相似,该示例实现了RequestAdapterRequestRetrier

我遇到的问题是func should(_ manager: SessionManager, retry request: Request, with error: Error, completion: @escaping RequestRetryCompletion)应该永远不会被调用func should(_ manager: SessionManager, retry request: Request, with error: Error, completion: @escaping RequestRetryCompletion) adapt的方法RequestAdapter实现并不被调用虽然。

调试时,我看到SessionDelegate仅在出现错误时才should(_,retry,with,completion)调用should(_,retry,with,completion) ,但是返回与Authorization问题相关的状态代码的请求似乎没有生成错误,因此该方法永远不会被调用。

我在这里想念什么吗?

也许您没有收到错误消息。 Alamofire不会将400个响应视为错误。 如果在接收400代码时想要出错,则应将validate()到请求。 如果是这种情况,您可以在此处找到更多信息。

完全按照文档中的示例操作,我的没有用。我已经按照示例所示使用了validate()

let sessionManager = SessionManager()
sessionManager.adapter = oauthHandler
sessionManager.retrier = oauthHandler
let urlString = "\(baseURLString)/some/endpoint"

sessionManager.request(urlString).validate().responseJSON { response in
debugPrint(response)
}

尽管在用Alamofire.SessionManager.default替换SessionManager()Alamofire.SessionManager.defaultfunc should(_ manager: SessionManager, retry request: Request, with error: Error, completion: @escaping RequestRetryCompletion)方法func should(_ manager: SessionManager, retry request: Request, with error: Error, completion: @escaping RequestRetryCompletion)

let sessionManager = Alamofire.SessionManager.default

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM