监听所有未捕获错误事件并记录到日志中

This commit is contained in:
lyswhut
2019-12-27 21:42:19 +08:00
parent a50ecff189
commit c81171a39e
3 changed files with 15 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
const { log } = require('./utils')
process.on('uncaughtException', function(err) {
console.error('An uncaught error occurred!')
console.error(err)
log.error(err)
})
process.on('unhandledRejection', (reason, p) => {
console.error('Unhandled Rejection at: Promise ', p)
console.error(' reason: ', reason)
log.error(reason)
})