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

Validation errors should be handled without exceptions #3

Open
baratgabor opened this issue Feb 17, 2021 · 0 comments
Open

Validation errors should be handled without exceptions #3

baratgabor opened this issue Feb 17, 2021 · 0 comments
Labels
backend enhancement New feature or request

Comments

@baratgabor
Copy link
Owner

Currently all validations errors are handled by throwing exceptions, which is arguably not an elegant or clean solution (nor is it efficient from a request handling performance perspective). And handling validation via exceptions is a frequent matter of contention in the developer community. So it would be great to showcase a different solution.

The solution has to still keep API concerns out of the application layer, so setting or returning any sort of response is out of the question.

The best candidate is most likely implementing a response model that is used universally by all request handlers, and it would contain – besides the return value, if any – whether the operation was successful, and if not, the validation errors that has occurred.

The MediatR IPipelineBehavior responsible for request validation also should adapt to this mechanism.

@baratgabor baratgabor added enhancement New feature or request backend labels Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant