如何让express.js捕获并报告AJAX调用中的运行时异常

时间:2021-01-05 20:22:00

I've found that when I have runtime errors (for example, reading an undefined property from an object) in a GET handler in express.js, Express is great at giving me feedback in the browser as to what the problem is and with a full stack trace.

我发现当我在express.js中的GET处理程序中遇到运行时错误(例如,从对象中读取未定义的属性)时,Express非常善于在浏览器中向我提供有关问题的反馈以及全栈跟踪。

However, when I have runtime errors as a result of an Ajax POST call, I don't get the same level of feedback and the Node console is sadly silent on the matter.

但是,当我因Ajax POST调用而遇到运行时错误时,我没有得到相同级别的反馈,并且Node控制台对此事件感到遗憾。

Is this an Express configuration issue?

这是Express配置问题吗?

1 个解决方案

#1


12  

Found the answer to my own questions...

找到了我自己的问题的答案......

You need to configure express's error handler to dump exceptions.

您需要配置express的错误处理程序来转储异常。

    app.use(express.errorHandler({showStack: true, dumpExceptions: true}));

#1


12  

Found the answer to my own questions...

找到了我自己的问题的答案......

You need to configure express's error handler to dump exceptions.

您需要配置express的错误处理程序来转储异常。

    app.use(express.errorHandler({showStack: true, dumpExceptions: true}));