2012-04-19 11 views
6

500エラーページを表示します。使用process.on( 'uncaughtExceptionは、私は特急のアプリを開発してい

を私は現在、私のserver.jsに以下の持っている

process.on('uncaughtException', function (err) { 
    console.log("UNCAUGHT EXCEPTION "); 
    console.log("[Inside 'uncaughtException' event] " + err.stack || err.message); 
}); 

クラッシュサーバーを停止しますエラーがありますたびに、しかし、それだけでそこに座っている...

は、それがエラーの詳細と500エラーページを送信するために代わりのにconsole.log可能ですか?

答えて

8

私は考えていませんuncaughtExceptionから応答を行うことができます。これは、要求が発生していない場合でも発生する可能性があるためです。あなたの他のapp.use文以下app.use(function(err, req, res, next){ // your logic });を追加し、ExpressJS Error Handlingパー

app.error(function(err, req, res, next){ 
    //check error information and respond accordingly 
}); 
+2

動作しません。 'app.error'は定義されていません。おそらくExpressJS APIは、この回答が投稿されてから変更されています(2年以上前)。 ExpressJSの例外処理については、http://expressjs.com/guide.html#error-handling –

+0

を参照してください。app.errorは関数ではありません。 –

4

エクスプレス自体はそうのような、ルート内のhandle errorsへの道を提供します。

例:

app.use(function(err, req, res, next){ 
    console.log(err.stack); 
    // additional logic, like emailing OPS staff w/ stack trace 
}); 
関連する問題