Bones's custom logger middleware sends any captured errors directly to the client.
Unfortunately, there seems to be a bug — in at least some cases, this results in an empty JSON object showing up in the client side. We could omit the stack trace by doing a res.send(err.toString()), resulting in an HTML page with just the error message. If we also want the stack trace, we might have to do some more work. In any case though, it would be good to track down and understand precisely why res.send(err) results in an empty JSON response. I have a suspicion it may have to do with the default behavior for calling toJSON on an Error object, but that's just a hunch, I haven't looked into it yet.
Also, we may want to distinguish between production and development behavior here, if only for the sake of demonstrating good practices (and maybe init-time branching as a concept).
Bones's custom logger middleware sends any captured errors directly to the client.
Unfortunately, there seems to be a bug — in at least some cases, this results in an empty JSON object showing up in the client side. We could omit the stack trace by doing a
res.send(err.toString())
, resulting in an HTML page with just the error message. If we also want the stack trace, we might have to do some more work. In any case though, it would be good to track down and understand precisely whyres.send(err)
results in an empty JSON response. I have a suspicion it may have to do with the default behavior for callingtoJSON
on an Error object, but that's just a hunch, I haven't looked into it yet.Also, we may want to distinguish between production and development behavior here, if only for the sake of demonstrating good practices (and maybe init-time branching as a concept).