jshttp / http-assert

assert with status codes
MIT License
151 stars 14 forks source link

May I response a json? #7

Closed libook closed 7 years ago

libook commented 8 years ago

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?

sorahn commented 7 years ago

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

jonathanong commented 7 years ago

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

libook commented 7 years ago

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.

dougwilson commented 7 years ago

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.