提交 8f7aa5b8 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

clean(code): keep unhandledRejection only in config.ts

上级 59d4db55
......@@ -10,10 +10,26 @@ import { log } from 'brolog'
import { Puppet } from './puppet'
const level = process.env['WECHATY_LOG']
if (level) {
log.level(level.toLowerCase())
log.silly('Brolog', 'WECHATY_LOG set level to %s', level)
const logLevel = process.env['WECHATY_LOG']
if (logLevel) {
log.level(logLevel.toLowerCase())
log.silly('Brolog', 'WECHATY_LOG set level to %s', logLevel)
}
/**
* to handle unhandled exceptions
*/
if (/verbose|silly/i.test(logLevel)) {
log.info('Config', 'registering process.on("unhandledRejection") for development/debug')
process.on('unhandledRejection', (reason, promise) => {
log.error('Config', '###########################')
log.error('Config', 'unhandledRejection: %s %s', reason, promise)
log.error('Config', '###########################')
promise.catch(err => {
log.error('Config', 'unhandledRejection::catch(%s)', err.message)
console.error('Config', err) // I don't know if log.error has similar full trace print support like console.error
})
})
}
export type PuppetName = 'web' | 'android' | 'ios'
......@@ -218,23 +234,6 @@ if (!global['WECHATY_CONFIG_INSTANCE_COUNTER']) {
}
global['WECHATY_CONFIG_INSTANCE_COUNTER']++
/**
* to handle unhandled exceptions
*/
const logLevel = process.env['WECHATY_LOG']
if (/verbose|silly/i.test(logLevel)) {
log.verbose('Config', 'registering process.on("unhandledRejection")')
process.on('unhandledRejection', (reason, promise) => {
log.error('Config', '###########################')
log.error('Config', 'unhandledRejection: %s %s', reason, promise)
log.error('Config', '###########################')
promise.catch(err => {
log.error('Config', 'unhandledRejection::catch(%s)', err.message)
console.error('Config', err) // I don't know if log.error has similar full trace print support like console.error
})
})
}
export {
log,
}
......
......@@ -17,11 +17,11 @@ import Server from '../../src/puppet-web/server'
// import { spy } from 'sinon'
process.on('unhandledRejection', (reason, p) => {
console.log('!!!!!!! unhandledRejection in puppet-web.spec.ts')
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason)
console.log('!!!!!!!')
})
// process.on('unhandledRejection', (reason, p) => {
// console.log('!!!!!!! unhandledRejection in puppet-web.spec.ts')
// console.log('Unhandled Rejection at: Promise', p, 'reason:', reason)
// console.log('!!!!!!!')
// })
/**
* the reason why use `test.serial` here is:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册