使用process.on('uncaughtException显示一个500错误页面 [英] Use process.on('uncaughtException to show a 500 error page
本文介绍了使用process.on('uncaughtException显示一个500错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个快速应用程序。
I'm developing an express app.
我目前在我的server.js中有以下内容
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...
是否可以代替console.log发送带有错误详细信息的500错误页面?
is it possible to instead of console.log, to send a 500 error page with the error details?
推荐答案
我不认为你可以从 uncaughtException
内做出回应,因为即使没有请求发生也可能发生。
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本身提供了一种方法来处理错误,如下所示:
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
});
这篇关于使用process.on('uncaughtException显示一个500错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文