jshttp/http-assert

May I response a json?

libook opened this issue · 4 comments

I can use http-assert in this way:

this.assert(this.request.body.urlId, 400, 'There should be an url ID.');

But in many times, I want to response a json like this:

this.assert(this.request.body.urlId, 400, {"message":"There should be an url ID.","anotherObject":{}});

This does not work probably.
So will you support this method?

@libook
This works: this.assert(param, 400, JSON.stringify({ msg: "It died" }))

what is the purpose of this? you can just have your error handle json stringify the error however you'd like

Well, http-assert just respond to client when there was an 'false'.
And it only respond the error message in body.
What if the client needs more information form body.
I think responding a JSON could be a perfect way.

I'm sorry, I don't understand what the ask even is here, after reading this. All this module does is throw an Error object; it doesn't do any serialization. Perhaps a PR may help communicate the idea across in code form.