如何find哪些promise在nodejs中未处理UnhandledPromiseRejectionWarning?
从版本7的nodejs有asynchronous等待处理承诺的sintactic糖,在我的apis下面的警告经常出现:
(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.
不幸的是,没有提到渔获缺失的地方。 有没有办法find它没有检查每个try catch块?
监听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 });