No, this is not intended behaviour. Normally it should call .then()
on HTTP 2xx
and .catch()
on HTTP 4xx
and HTTP 5xx
(not sure about the others).
The described behaviour is probably caused by another .catch()
returning a resolved promise.
In a slightly changed example:
//In some Service:
function getResources()
{
$http.get('/some/resource')
// /some/resource --> HTTP 400
.then(function(response)
{
console.log('service success');
return response;
})
.catch(function(reason)
{
console.log('service error');
// IMPORTANT: although this is returned
// in a .catch() it returns a resolved promise
return reason;
});
}
//In some Controller:
someService.getResources()
.then(function(response)
{
console.log('controller success');
})
.catch(function(reason)
{
console.log('controller error');
});
// Console:
// - service error
// - controller success
Note that this can also be caused by a registered http interceptor
:
$httpProvider.interceptors.push(function($q)
{
return {
'response': function(response)
{
// do something
return response;
},
'responseError': function(rejection)
{
// do something
return rejection; // <-- this causes the problem
// instead do
return $q.reject(rejection);
}
}
}