Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

access res/req from process uncaughtException

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!

like image 807
Leabdalla Avatar asked Jun 20 '26 06:06

Leabdalla


1 Answers

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({ ... });
});
like image 57
Alex Netkachov Avatar answered Jun 25 '26 04:06

Alex Netkachov