May I response a json?
libook opened this issue · 4 comments
libook commented
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?
jonathanong commented
what is the purpose of this? you can just have your error handle json stringify the error however you'd like
libook commented
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
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.