在解决的承诺中捕捉不会更改响应。STATUS()

发布于 2025-02-06 03:16:06 字数 1113 浏览 1 评论 0原文

如果找到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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文