【发布时间】:2016-03-04 06:19:09
【问题描述】:
如何使用 Promise 链接调用下一个错误函数?
我以为错误函数中的 return 会自动调用下一个错误函数。
//Called in a controller
dataService.saveRequest()
.then(function result(res){
//Logged when the service sends back a result
console.log("finished");
}, function error(error){
//Logged when the service sends back an error
//THIS DOES NOT GET CALLED
console.log("error from controller");
});
//INSIDE THE SERVICE
this.saveRequest = function(){
return $http.post('rest/request/send-request', someData)
.then(function(result){
//Goes, as expected, into the success function in the controller
return result.data;
}, function(error){
//Does NOT go into the next error function
//I need the error function to execute in the controller
return error;
});
};
【问题讨论】:
标签: javascript angularjs promise