版本 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.
不幸的是,没有提到 catch 丢失的行。有没有办法在不检查每个 try/catch 块的情况下找到它?
原文由 user1658162 发布,翻译遵循 CC BY-SA 4.0 许可协议
听
unhandledRejection
进程事件。