我建议你补充一下
unhandledRejection
Node.js
未处理弹射
每当承诺被拒绝并且在事件循环的一个回合内没有错误处理程序附加到该承诺时,就会发出事件。当使用承诺编程时,异常被封装为“拒绝的承诺”。可以使用
promise.catch()
并通过承诺链传播。这个
未处理弹射
下面是如何再次使用Node.js提供的示例:
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at:', p, 'reason:', reason);
// application specific logging, throwing an error, or other logic here
});
somePromise.then((res) => {
return reportToUser(JSON.pasre(res)); // note the typo (`pasre`)
}); // no `.catch()` or `.then()`