我正在使用 angular-http-auth 包,它是 angular 的 HTTP 拦截器,可检测 401 非授权请求并允许延迟请求并在其之前执行授权。
但是,我有一个问题,授权是另一个请求,也可能触发 401 错误。我想取消这些请求,因为我会重新发出它们。
本质上,我收到了这样一个事件:
$scope.$on('event:auth-loginRequired', function (event, httpHeader) {
})
其中 event 是 JSevent
对象,httpHeader
是一组关于 401 请求的数据。
httpHeader 示例:
{
"data": "",
"status": 401,
"config": {
"method": "POST",
"transformRequest": [null],
"transformResponse": [null],
"data": { "password": "wrqwfqwvcfqwfcq", "userName": "user123"},
"url": "https://localhost:44300/api/authentication",
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json;charset=utf-8",
"X-Auth-Token": "73r23r"
},
"withCredentials": true
},
"statusText": "Unauthorized"
}
因此,我分析httpHeader.config.url
并且我可能希望取消一些特定的 URL 请求(让其他未处理的请求保持不变并等待),最好基于httpHeader
收到的事件信息。我怎么能这样做?