如何在unhandledRejection上发送500错误
process.on("unhandledRejection", function(promise, reason){
// deal with the rejection here.
console.log('global error handler');
console.log(reason);
});
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.json({"error": err.message});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.json({"error": err.message});
});