我仍然是相当新的承诺,目前正在使用蓝鸟,但我有一个场景,我不太确定如何最好地处理它.
例如,我在快递应用程序中有一个承诺链,如下所示:
repository.Query(getAccountByIdQuery)
.catch(function(error){
res.status(404).send({ error: "No account found with this Id" });
})
.then(convertDocumentToModel)
.then(verifyOldPassword)
.catch(function(error) {
res.status(406).send({ OldPassword: error });
})
.then(changePassword)
.then(function(){
res.status(200).send();
})
.catch(function(error){
console.log(error);
res.status(500).send({ error: "Unable to change password" });
});
Run Code Online (Sandbox Code Playgroud)
所以我追求的行为是:
所以,目前抓到似乎没有停止的链接,这是有道理的,所以我想知道如果有,我以某种方式迫使链停在基于错误的某一点的方式,或是否有更好的办法构造它以获得某种形式的分支行为,就像有一种情况一样if X do Y else Z
.
任何帮助都会很棒.