From 5fed56db51930225a7a4ae2d5e99dc289485ad1d Mon Sep 17 00:00:00 2001 From: dsanz Date: Tue, 28 Mar 2017 13:50:16 +0200 Subject: [PATCH 1/2] Domain validation errors must throw domain exceptions. --- .../Application/Decorators/ValidatorDecorator.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Services/Ordering/Ordering.API/Application/Decorators/ValidatorDecorator.cs b/src/Services/Ordering/Ordering.API/Application/Decorators/ValidatorDecorator.cs index 5bdff8330..20318adf8 100644 --- a/src/Services/Ordering/Ordering.API/Application/Decorators/ValidatorDecorator.cs +++ b/src/Services/Ordering/Ordering.API/Application/Decorators/ValidatorDecorator.cs @@ -1,5 +1,6 @@ using FluentValidation; using MediatR; +using Ordering.Domain.Exceptions; using System; using System.Collections.Generic; using System.Linq; @@ -33,8 +34,8 @@ namespace Ordering.API.Application.Decorators if (failures.Any()) { - throw new ValidationException( - $"Command Validation Errors for type {typeof(TRequest).Name}", failures); + throw new OrderingDomainException( + $"Command Validation Errors for type {typeof(TRequest).Name}", new ValidationException("Validation exception", failures)); } var response = await _inner.Handle(message); From e596926b9b91b8d7deae156e96e8e83f642b3321 Mon Sep 17 00:00:00 2001 From: dsanz Date: Tue, 28 Mar 2017 13:55:27 +0200 Subject: [PATCH 2/2] add comment about known bug in .net core 1.1 --- .../Infrastructure/Filters/HttpGlobalExceptionFilter.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/Filters/HttpGlobalExceptionFilter.cs b/src/Services/Ordering/Ordering.API/Infrastructure/Filters/HttpGlobalExceptionFilter.cs index 25cf46830..7d19815b9 100644 --- a/src/Services/Ordering/Ordering.API/Infrastructure/Filters/HttpGlobalExceptionFilter.cs +++ b/src/Services/Ordering/Ordering.API/Infrastructure/Filters/HttpGlobalExceptionFilter.cs @@ -32,6 +32,8 @@ Messages = new[] { context.Exception.Message } }; + // Result asigned to a result object but in destiny the response is empty. This is a known bug of .net core 1.1 + //It will be fixed in .net core 1.1.2. See https://github.com/aspnet/Mvc/issues/5594 for more information context.Result = new BadRequestObjectResult(json); context.HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest; } @@ -47,6 +49,8 @@ json.DeveloperMeesage = context.Exception; } + // Result asigned to a result object but in destiny the response is empty. This is a known bug of .net core 1.1 + // It will be fixed in .net core 1.1.2. See https://github.com/aspnet/Mvc/issues/5594 for more information context.Result = new InternalServerErrorObjectResult(json); context.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; }