Javascript 在未处理的情况下发送500

Javascript 在未处理的情况下发送500,javascript,node.js,express,Javascript,Node.js,Express,如何在未处理的弹出上发送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(

如何在未处理的弹出上发送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});
});

您的错误处理程序是正确的,您可以发送一个带有代码的示例如何抛出错误?我想知道如何在未处理的情况下向客户端发送500个错误