gpt4 book ai didi

javascript - promise : go to next error function

转载 作者:行者123 更新时间:2023-11-29 10:10:46 25 4
gpt4 key购买 nike

<分区>

如何使用 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;
});

};

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com