-
Notifications
You must be signed in to change notification settings - Fork 25
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
Comments
@dbleakley 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: 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. |
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.
The text was updated successfully, but these errors were encountered: