-
Notifications
You must be signed in to change notification settings - Fork 31
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
[question] Add extra fields to response #80
Comments
If you are sending the response as JSON, the easiest way is to simply override the |
I have the following custom error:
Which is called like this:
However, from my So, I've used
I was just wondering if it's the right way to go or if I'm hijacking the |
@tsm91 I think you settled on not exposing it by default. Since you were about to expose it, can I assume it's ok for my to use |
@maoueh i would say yes, anything goes but i believe the usage for context property would be for internal logging mechanism, so one who reads the logs can understand a bit more about the error itself also, why would you want to send back validation data to client? Client should handle validation errors before form is submitted. |
The client should indeed, and it will, but backend could do some validations the client won't do (checking for a duplicated or something more fancy). And I would like to send this validation. Also, for those use the API more in cURL/Postman way, not having the actual messages is a pain. So I always prefer to send validation errors back to client so it is able to display them to user. |
why not? I usually got async validators when the situation requires it. For signup you implement an endpoint to check if the email address provided is taken or not. Based on that u return a http 400 which the client intercepts as email addr is taken.
I use postman as well. I usually log the extra information to console. You dont have to send it back in the response. Also with Bunyan u could log these infos in production as well. What i plan on doing is investigate https://github.com/restify/errors#bunyan-support and https://github.com/trentm/node-bunyan. To implement a proper logging system that works in dev and prod as well. |
@maoueh what i did is implemented a loggerService, which can properly write errors to process.stdout on serverside this way when you test api-s you can read the logs in the console instead of sending validation errors to client. Link to example usage part 1, part 2, serializer implementation it looks like this |
I see, by design strictly only
code
andmessage
are being passed to http response body.https://github.com/restify/errors/blob/master/lib/baseClasses/HttpError.js#L92
https://github.com/restify/errors/blob/master/lib/baseClasses/HttpError.js#L147
Imagine a scenario when you want to pass down some extra metadata in the error response. For example validation details:
How do you guys pass extra error metadata in http response?
The text was updated successfully, but these errors were encountered: