在解决的承诺中捕捉不会更改响应。STATUS()
如果找到Promise>,请使用两种数据类型,如果找到
:
- 如果找不到
card
,则拒绝父母的承诺,如果发现 - 第二/儿童承诺如果
终端
找不到。
预期行为:
a)如果找不到card
运行:
response.status(293);
response.end();
a)如果终端
未找到运行:
response.status(292);
response.end();
代码示例
getCard(cardID)
.then((card: Card) => {
getTerminal(terminalID)
.then((terminal: Terminal) => {
// do smth
})
.catch((e) => {
console.log(e); // log works fine
response.status(292);
// terminal does not exist
});
})
.catch((e) => {
console.log(e);
response.status(293);
// card doesn't exist
})
.finally(() => {
response.end();
// close connection
});
问题:
服务器返回200
在所有情况下,状态除293
,第一个catch()
,这是唯一按预期执行的。我猜想这应该是依次的承诺,而不是基于儿童的承诺。我们如何实现?
There are two data types to get using promise
if they are found:
- The parent promise is rejected if the
card
is not found - The second/child promise is expected to reject if the
terminal
is not found.
Expected behavior:
a) If card
is not found run:
response.status(293);
response.end();
a) If terminal
is not found run:
response.status(292);
response.end();
Code example
getCard(cardID)
.then((card: Card) => {
getTerminal(terminalID)
.then((terminal: Terminal) => {
// do smth
})
.catch((e) => {
console.log(e); // log works fine
response.status(292);
// terminal does not exist
});
})
.catch((e) => {
console.log(e);
response.status(293);
// card doesn't exist
})
.finally(() => {
response.end();
// close connection
});
Problem:
The server returns 200
status in all cases other than 293
, the first catch()
, which is the only one that is executed as expected. I have a guess that it should be sequential promises, not child-parent based. How do we achieve that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论