From 51b8b348c57db055572c0a88759c86ca6e62bb21 Mon Sep 17 00:00:00 2001 From: welefen Date: Wed, 22 Jul 2015 19:44:51 +0800 Subject: [PATCH] capture error in app start --- src/core/app.js | 3 ++- src/index.js | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core/app.js b/src/core/app.js index afd66646..8a454d25 100644 --- a/src/core/app.js +++ b/src/core/app.js @@ -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); diff --git a/src/index.js b/src/index.js index dd2781b9..82bc8b0b 100644 --- a/src/index.js +++ b/src/index.js @@ -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);