app.js
_app.configure(function()
{
/**
* app setup
*/
_app.set('port', process.env.PORT || 3000);
_app.use(express.methodOverride());
_app.use(function(req, res, next){
console.log('%s %s', req.method, req.url);
next();
});
_app.use(_app.router);
_app.use(express.static(__dirname+'/public'));
});
process.on('uncaughtException', function (err, req, res) {
console.log( res );
_winston.error(err.message, err.code);
});
When the uncaught occurs, I can show messages in console, but I want too send a JSON response to browser. How can I do this? How can I access res/req from uncaughtException?
thanks!
It is not possible, as far as I know, because an uncaught exception may happen not only in the express callback but anywhere in the code. What you probably need is to use the express error handler:
_app.error(function(err, req, res, next) {
res.json({ ... });
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With