, .fail() . :
promise.then(function(){
console.log('Then 1');
throw new Error('Error');
})
.then(function(){
console.log('Then 2');
})
.then(function(){
console.log('Then 3');
})
.fail(function(){
console.log('Fail 1');
})
.then(function(){
console.log('Then 4');
});
:
> Then 1
> Fail 1
> Then 4
.Fail() .then(), .then(). , .fail(), , .then() .
, _handleFail() , .then() ( , .fail().
, :
angular.module( '')
.factory('dataStore', function() {
var _handleFail = function(error) {
if (error && error.status && error.status === 401) {
throw new Error('Unauthorized');
}
};
function saveEntity(entity) {
return manager.saveChanges(entity).fail(_handleFail);
}