我的代码中有一个错误,触发了警告:
DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
当这些发生时,有没有办法让Node终止?
答案 0 :(得分:7)
process
会为这些发出unhandledRejection
event,所以:
process.on('unhandledRejection', error => {
throw error;
});