【问题标题】:How to avoid http2 connect from crashing Node.js如何避免 http2 连接崩溃 Node.js
【发布时间】:2020-05-17 12:44:17
【问题描述】:
  const client = http2.
    connect('https://domain.doesnt.exist').
    on('error', e => {
      console.error(e.message);
    });

在 Node.js 13.6.0 上,即使提供了错误侦听器,上述代码也会导致整个进程崩溃。

我将如何避免它?

【问题讨论】:

    标签: node.js http2


    【解决方案1】:

    您可以使用uncaughtException 事件记录所有未捕获的异常..

    process.on('uncaughtException', err => {
      console.log(err.message);
      console.log(err.stack);
      process.exit(1)
    })
    

    【讨论】:

    • 我可以,但它也会捕获其他异常。我只想忽略来自 http2.connect 的异常。
    猜你喜欢
    • 2018-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多