简体   繁体   中英

How to avoid http2 connect from crashing Node.js

  const client = http2.
    connect('https://domain.doesnt.exist').
    on('error', e => {
      console.error(e.message);
    });

On Node.js 13.6.0, even when provided an error listener, the above code would crash the entire process.

How will I be able to avoid it?

you can use uncaughtException event to log all exceptions not been caught..

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM