Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get express.js to catch and report runtime exceptions in AJAX calls

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.

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.

Is this an Express configuration issue?

like image 594
Greg Avatar asked Nov 04 '11 20:11

Greg


People also ask

Does express js use Ajax?

expressjs is serverside code so it can't use jquery ajax like that. jQuery. ajax() can only be used at view when you load your page in the browser.

Is Express JS unmaintained?

It is unmaintained Express has not been updated for years, and its next version has been in alpha for 6 years. People may think it is not updated because the API is stable and does not need change. The reality is: Express does not know how to handle async/await .


1 Answers

Found the answer to my own questions...

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

    app.use(express.errorHandler({showStack: true, dumpExceptions: true}));
like image 180
Greg Avatar answered Sep 30 '22 00:09

Greg