版本7中的Node.js具有用于处理promise的async / await语法糖,现在在我的代码中经常出现以下警告:
(node:11057) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ReferenceError: Error: Can't set headers after they are sent. (node:11057) 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.
不幸的是,没有提到丢失渔获物的那一行。有没有找到所有方法而不检查每个try / catch块的方法?
监听unhandledRejection进程事件。
unhandledRejection
process.on('unhandledRejection', (reason, p) => { console.log('Unhandled Rejection at: Promise', p, 'reason:', reason); // application specific logging, throwing an error, or other logic here });