AngularJS 带有未定义参数的 $http promise 回调
AngularJS $http promise callback with undefined parameter
我有一个像这样的简单 httpcall
$http({
"params": {
permission
},
"cache": true,
"method": "GET",
"url": "base/authorize/any/"
}).then(function successCallback(response){...},function failCallback(response){...});
在后端调用它时 returns 一个 Http 400 错误请求。没什么特别的。
奇怪的是:Backend响应后执行了successCallback。我本以为 faliCallback 会被执行。
甚至更奇怪:在 successCallback 响应中未定义。
你们中的任何人都可以解释这种行为吗?
如果有任何帮助,我将不胜感激。
编辑 1:
以防万一需要信息。这个调用其实是要被这个拦截器拦截的
angular.module("app").factory("UnauthorizedInterceptor",
UnauthorizedInterceptor);
function UnauthorizedInterceptor($injector) {
const service = {
responseError
};
function responseError(response) {
if (response.status === 401) {
$injector.get("AuthenticationService").Logout();
$injector.get("$state").go("home", {
logout : true
});
}
}
return service;
}
尝试return responseError 拦截器中被拒绝的承诺:
return $q.reject(response);
你可以查看官方的例子docs and in this issue on GitHub
我有一个像这样的简单 httpcall
$http({
"params": {
permission
},
"cache": true,
"method": "GET",
"url": "base/authorize/any/"
}).then(function successCallback(response){...},function failCallback(response){...});
在后端调用它时 returns 一个 Http 400 错误请求。没什么特别的。
奇怪的是:Backend响应后执行了successCallback。我本以为 faliCallback 会被执行。
甚至更奇怪:在 successCallback 响应中未定义。
你们中的任何人都可以解释这种行为吗? 如果有任何帮助,我将不胜感激。
编辑 1: 以防万一需要信息。这个调用其实是要被这个拦截器拦截的
angular.module("app").factory("UnauthorizedInterceptor",
UnauthorizedInterceptor);
function UnauthorizedInterceptor($injector) {
const service = {
responseError
};
function responseError(response) {
if (response.status === 401) {
$injector.get("AuthenticationService").Logout();
$injector.get("$state").go("home", {
logout : true
});
}
}
return service;
}
尝试return responseError 拦截器中被拒绝的承诺:
return $q.reject(response);
你可以查看官方的例子docs and in this issue on GitHub