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

Allow better customization of validation and auth errors #16

Closed
pwwolf opened this issue May 7, 2015 · 1 comment
Closed

Allow better customization of validation and auth errors #16

pwwolf opened this issue May 7, 2015 · 1 comment

Comments

@pwwolf
Copy link

pwwolf commented May 7, 2015

Thinking about letting the swagger validators return an Error rather than returning a response themselves. Then Express error middleware can handle the errors and formatting them however they'd like.

pwwolf pushed a commit that referenced this issue May 8, 2015
@pwwolf
Copy link
Author

pwwolf commented May 8, 2015

@dbleakley
Darrell, I took a first stab at this, but I think it's going to need some tweaking to completely satisfy your use case.

The swagger validator now creates Errors if it hits a validation problem. The errors are passed off via a call to next(error) so that the error middleware can deal with it however it wants. The errors will have a name field that you can check to see what kind of error it is. In the case of the swagger validation, it returns an error with name ValidationError.

There's a built-in error handler that formats validation errors similar to your format. If you want to handle them differently, see the sprout-server/examples/swagger and check how it registers its own error middleware.

Couple of notes:
When we do the swagger validation, some errors are generated by our swagger validator, such as missing required query params or headers. In those cases there's the Error just contains a simple message such as "Missing require parameter X".

However, in all other cases, or in the case of validating a body, the validation failures are being generated by the tv4 library. So we create a single ValidatorError, and embed all the tv4-generated errors under the subErrors field.

What I still need to do is take the ValidatorError we create for missing fields and make them look more like the tv4-generated ValidatorErrors so that it contains richer set of information about the cause of the validation failure.

Let me know how this looks and we can iterate on it. Or you can submit push requests.

pwwolf pushed a commit that referenced this issue Jan 13, 2016
@pwwolf pwwolf closed this as completed Jan 19, 2016
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

1 participant