如何从错误跟踪中找到承诺的成功轨迹?

问题描述 投票:0回答:1

所以我有这个代码:

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”轨道。我怎样才能做到这一点?我的一个承诺有一个可能的备份计划,我想在错误方法中执行并执行其余的成功。

node.js promise
1个回答
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'))
© www.soinside.com 2019 - 2024. All rights reserved.