capture error in app start

This commit is contained in:
welefen 2015-07-22 19:44:51 +08:00
parent 8079f37924
commit 51b8b348c5
2 changed files with 14 additions and 2 deletions

View File

@ -172,7 +172,8 @@ export default class extends think.base {
//create server
let server = http.createServer(callback);
if (think.config('websocket.on')) {
(new websocket(server, this)).run();
let instance = new websocket(server, this);
instance.run();
}
server.listen(port, host);
this.logPid(port);

View File

@ -374,6 +374,16 @@ export default class {
}, 1000);
thinkCache(thinkCache.TIMER, 'auto_reload', timer);
}
/**
* capture error
* @return {} []
*/
captureError(){
process.on('uncaughtException', function(err){
err = think.error(err, 'port:' + think.config('port'));
think.log(err);
})
}
/**
* start
* @return {} []
@ -381,6 +391,7 @@ export default class {
start(){
this.checkEnv();
this.load();
this.captureError();
if (think.config('auto_reload')) {
this.autoReload();
}
@ -390,8 +401,8 @@ export default class {
* @return {} []
*/
async run(){
this.start();
try{
this.start();
await think.require('app').run();
}catch(err){
think.log(err);