baratgabor/MyWarehouse

Validation errors should be handled without exceptions

baratgabor opened this issue · 0 comments

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.