当承诺错误在第二个承诺中被调用时,是否有一个更简单/正确的方法,而不必每次手动拒绝它的catch块中的承诺?
promise1() {
return this.$http
.get("/url")
.then(response => {
// do things
})
.catch(err => {
return Promise.reject(err);
// don't want to have to call this in every single catch block
// ideally errors would bubble up when called from second promise
});
}
在第二个承诺中,我希望在第一个承诺失败时触发catch块(而不必手动拒绝它)
promise2(){
return .promise1()
.then(response => {})
.catch(err => {
// error bubbled up from first promise
}
});
}