How to handle errors in http requests?
Here the full error is returned to the client.. How to write the error to the log and return Fatal error to the client?
Express v4.4.4
var express = require('express'),
app = express(),
domain = require('domain'),
port = 3000;
app.use(function(err, req, res, next){
console.error(err.stack);
res.send('Fatal error!', 500);
});
app.get('/', function(req, res){
var d = domain.create();
d.on('error', function(err){
console.error('Error', err);
res.send('Fatal error!', 500);
});
d.add(req);
d.add(res);
d.run(function(){
// a is undefined
a.ddd();
res.send('Success!');
});
})
.listen(port, function(){
console.log('Express server listening on port '+port);
});