MediatR.Extensions.FluentValidation.AspNetCore icon indicating copy to clipboard operation
MediatR.Extensions.FluentValidation.AspNetCore copied to clipboard

Returning errors instead of throwing?

Open lonix1 opened this issue 4 years ago • 2 comments

Using exceptions for flow control is very "heavy".

Anyone figure out how to return a result with errors, instead of throwing exceptions?

lonix1 avatar Oct 07 '21 03:10 lonix1

You are right. But do you know any other way to pass validation failure to exception handler on middleware level?

GetoXs avatar Oct 10 '21 12:10 GetoXs

Yes it can be done using a little bit of reflection. It feels "dirty", but it's still faster than using exceptions. (Doing it that way there is no need for exception handlers, the conversion from validation failure to HTTP response can be done in the controller.)

However I still hope there is another way, without exceptions and reflection.

(Feel free to close. Take a look at that link it's excellent.)

lonix1 avatar Oct 10 '21 12:10 lonix1