I have a function called athat accepts a callback that is called with an error if one exists.
acalled in the express route request. If there is an error, the error should be the answer to the request.
function a(cb) {
cb(new Error('Some error message'))
}
app.get('/', function (req, res) {
a(function (error) {
if (error) {
res.json(error, 400)
}
res.send('No error')
})
})
I looked at the code for Express, and it seems that res.jsonmine will be building error. However, the result of this is an empty string:
> var e = new Error('Some error message')
undefined
> JSON.stringify(e)
'{}'
> e.message
'Some error message'
, , , , toString . , , API Node, . - error , :
res.json({ error: error.message }, 400)
user1082754