所以我有这段代码:
aPromise
.then(function(result2){return aFailingPromise;}, function(error) {...})
.then(function(result1){return newPromise;}, function(error) {/*Catch failure, do backup things and go back to correct track*/})
.then(function(result3){return promise;}, function(error) {...});
当发生故障时,我传递给promise链的每个错误方法都会被调用,并且不会返回到“success”轨道。我怎样才能做到这一点?我的一个承诺有一个可能的备份计划,我想在错误方法中执行并执行其余的成功。
答案 0 :(得分:0)
如果您没有在错误处理中抛出/拒绝
,则会返回成功Promise.reject(new Error('some error'))
.then(() => console.log('never reached'))
.catch(e => console.log(e.message)) // some error
.then(() => console.log('good again as the error is handled above'))
.catch(() => console.log('never reached'))