我有一个像这样的简单的httpcall
$http({
"params": {
permission
},
"cache": true,
"method": "GET",
"url": "base/authorize/any/"
}).then(function successCallback(response){...},function failCallback(response){...});
当调用它时,后端返回一个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;
}
答案 0 :(得分:1)
尝试在responseError拦截器中返回被拒绝的promise:
return $q.reject(response);
您可以查看官方docs和this issue on GitHub
中的示例