I expected that bad requests would fall in the function defined inside $http#error, but that does not happen. Instead I had to create an interceptor. And even though I know the status code should be 404, the returned status code in the response is 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!!
});
and here is the interceptor:
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-Why is this? 2-Is there a way to catch bad requests in $http#error? 3-Is there a way to get the actual 404 status code?