visionmedia/express — Issue #912: next()ing an error with json content type wont return formatted error
Author: tdfairbrother
Created: 2011-12-02 04:14:49+00:00
State: open

jQuery
$.ajax({url:"http://localhost:3000/nodeapi/error", dataType:'json'})

Express
app.get('/error', function(req, res, next) {
next(new Error('my custom error'))
})

Will produce
{"error":{}}

In development mode only.

It appears the line 78 of errorHandler.js does the following.

var json = JSON.stringify({ error: err });

Try the following in a browser to see the same problem
JSON.stringify(new Error('test'))

Cheers,

Tim