Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

May I response a json? #7

Closed
libook opened this issue Apr 24, 2016 · 4 comments
Closed

May I response a json? #7

libook opened this issue Apr 24, 2016 · 4 comments

Comments

@libook
Copy link

libook commented Apr 24, 2016

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
Copy link

sorahn commented Nov 25, 2016

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

@jonathanong
Copy link
Member

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

@libook
Copy link
Author

libook commented Dec 1, 2016

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants