【发布时间】:2015-12-19 23:57:21
【问题描述】:
我预计错误的请求会落在 $http#error 中定义的函数中,但这并没有发生。相反,我必须创建一个拦截器。即使我知道状态码应该是 404,响应中返回的状态码也是 0。
$http({url: "myurl", method: "GET"}).success(
function(data, status, headers, config) {
if (data.ret_code === 200) {
//do something
}
}).error(function(data, status, headers, config) {
//NEVER GETS HERE ON BAD REQUEST!!
});
这里是拦截器:
var interceptor = ['$q', function ($q) {
function success(response) {
return response;
}
function error(response) {
//ALWAYS 0!
var status = response.status;
return $q.reject(response);
}
return function (promise) {
return promise.then(success, error);
}
}];
1-这是为什么? 2-有没有办法在 $http#error 中捕获错误请求? 3-有没有办法获取实际的404状态码?
【问题讨论】:
-
它攻击你的服务器了吗?