diff --git a/src/ReC.API/Middleware/ExceptionHandlingMiddleware.cs b/src/ReC.API/Middleware/ExceptionHandlingMiddleware.cs index 0486ea6..c770712 100644 --- a/src/ReC.API/Middleware/ExceptionHandlingMiddleware.cs +++ b/src/ReC.API/Middleware/ExceptionHandlingMiddleware.cs @@ -1,4 +1,5 @@ using DigitalData.Core.Exceptions; +using FluentValidation; using ReC.Application.Common.Exceptions; using System.Net; using System.Text.Json; @@ -65,6 +66,11 @@ public class ExceptionHandlingMiddleware message = badRequestEx.Message; break; + case ValidationException validationEx: + context.Response.StatusCode = (int)HttpStatusCode.UnprocessableEntity; + message = "Validation failed: " + string.Join("; ", validationEx.Errors.Select(e => e.ErrorMessage)); + break; + case NotFoundException notFoundEx: context.Response.StatusCode = (int)HttpStatusCode.NotFound; message = notFoundEx.Message;