gpt4 book ai didi

node.js - 使用 process.on('uncaughtException 显示 500 错误页面

转载 作者:搜寻专家 更新时间:2023-10-31 22:28:18 24 4
gpt4 key购买 nike

我正在开发一个快速应用。

目前我的 server.js 中有以下内容

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

这会在每次出现错误时阻止服务器崩溃,但是,它只是坐在那里...

是否可以发送包含错误详细信息的 500 错误页面而不是 console.log?

最佳答案

我认为您无法从 uncaughtException 中进行响应,因为即使没有请求发生,也可能发生这种情况。

Express 本身提供了一种方式来handle errors在路线内,像这样:

app.error(function(err, req, res, next){
//check error information and respond accordingly
});

关于node.js - 使用 process.on('uncaughtException 显示 500 错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10221309/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com