Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use process.on('uncaughtException to show a 500 error page

I'm developing an express app.

I currently have the following in my server.js

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

Which stops the server crashing every time there's an error, however, it just sits there...

is it possible to instead of console.log, to send a 500 error page with the error details?

like image 774
Alex Avatar asked Apr 19 '12 03:04

Alex


1 Answers

I don't think you can from within the uncaughtException do a response since that could happen even when there is no request occurring.

Express itself provides a way to handle errors within routes, like so:

app.error(function(err, req, res, next){
    //check error information and respond accordingly
});
like image 116
Aaron Powell Avatar answered Oct 04 '22 00:10

Aaron Powell