Alamofire 4.0 RequestRetrier不应该被调用(_,retry,with,completion) [英] Alamofire 4.0 RequestRetrier should(_,retry,with,completion) not being called
问题描述
我正在使用Alamofire 4.0的 RequestRetrier
来控制对过期访问令牌的请求的重试。我正在文档此处。
I am using the RequestRetrier
of Alamofire 4.0 to control the retrying of requests for expired access token. I am following the documentation here.
我的实现与文档 OAuth2Handler
中提供的示例非常相似,该文档实现了 RequestAdapter
和 RequestRetrier
。
I have a very similar implementation to the example available in the documentation OAuth2Handler
which implements RequestAdapter
and RequestRetrier
.
我遇到的问题是 func应该(_经理:SessionManager,重试请求:请求,错误:错误,完成:@转义RequestRetryCompletion)
永远不会被调用。确实会调用 RequestAdapter
实现的 adapt
方法。
The issue I am encountering is that func should(_ manager: SessionManager, retry request: Request, with error: Error, completion: @escaping RequestRetryCompletion)
is never being called. The adapt
method of the RequestAdapter
implementation does get called though.
调试,我看到 SessionDelegate
仅在存在以下情况时调用应该(_,retry,with,completion)
错误,但请求返回与授权问题相关的状态代码,似乎没有生成错误,因此该方法永远不会被调用。
Debugging, I see that SessionDelegate
only calls should(_,retry,with,completion)
when there is an error, but requests that return status codes related to Authorization issues, don't seem to generate errors, so that method never gets called.
我在这里错过了什么吗?
Am I missing something here?
推荐答案
也许您没有收到错误消息。 Alamofire
不会将400个响应视为错误。如果在接收400个代码时遇到错误,则应将 validate()
链接到请求。
如果您是这种情况,可以在此处找到更多信息。
Maybe you are not getting an error. 400 responses aren't considered as error by Alamofire
. In case you want get an error when receiving a 400 code you should chain validate()
to the request.
If this is your case you can find more information here.
这篇关于Alamofire 4.0 RequestRetrier不应该被调用(_,retry,with,completion)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!