Nodejs: How to catch an exception from middleware?

By : Searle

I'm using node.js and the "less" compiler middleware:

app.configure(function() {
    // ...
    app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] }))
    // ...

Now i've got a faulty .less-file, but I can't find any docs on how to get the error message. The page I receive is this:

    <title>[object Object]</title>
      /* css stuff */
    <div id="wrapper">

      <h2><em>500</em> [object Object]</h2>
      <ul id="stacktrace"></ul>

So that's not helpful. Anybody got an idea?

By : Searle


Ah, ok, got it. The trick is to leave away the development errorHandler

app.configure('development', function() {
    // app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));

It seems to swallow calls to app.error, so now this works:

app.error(function(err, req, res, next) {
    sys.puts("APP.ERROR:"   sys.inspect(err));

This shows the correct error instead of [object Object]

By : Searle

This video can help you solving your question :)
By: admin