From c25e4d6254e430f657dc24c7f497fe05ff63e36a Mon Sep 17 00:00:00 2001 From: mehdihadeli Date: Thu, 15 Jun 2023 20:16:42 +0330 Subject: [PATCH] fix: :bug: bug fix in bad request exception --- .../Core/Exceptions/BadRequestException.cs | 2 +- .../CaptureExceptionMiddlewareExtensions.cs | 1 + .../Products/ProductConfigurations.cs | 6 +++--- .../Shared/CatalogsConfigurations.cs | 10 +++++++--- .../WebApplicationExtensions.Infrastructure.cs | 1 + 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Vertical.Slice.Template.Shared/Core/Exceptions/BadRequestException.cs b/src/Vertical.Slice.Template.Shared/Core/Exceptions/BadRequestException.cs index d67f1df..ae429db 100644 --- a/src/Vertical.Slice.Template.Shared/Core/Exceptions/BadRequestException.cs +++ b/src/Vertical.Slice.Template.Shared/Core/Exceptions/BadRequestException.cs @@ -5,5 +5,5 @@ namespace Vertical.Slice.Template.Shared.Core.Exceptions; public class BadRequestException : CustomException { public BadRequestException(string message, Exception? innerException = null) - : base(message, StatusCodes.Status404NotFound, innerException) { } + : base(message, StatusCodes.Status400BadRequest, innerException) { } } diff --git a/src/Vertical.Slice.Template.Shared/Web/ProblemDetail/Middlewares/CaptureExceptionMiddleware/CaptureExceptionMiddlewareExtensions.cs b/src/Vertical.Slice.Template.Shared/Web/ProblemDetail/Middlewares/CaptureExceptionMiddleware/CaptureExceptionMiddlewareExtensions.cs index 45b8249..9b9a070 100644 --- a/src/Vertical.Slice.Template.Shared/Web/ProblemDetail/Middlewares/CaptureExceptionMiddleware/CaptureExceptionMiddlewareExtensions.cs +++ b/src/Vertical.Slice.Template.Shared/Web/ProblemDetail/Middlewares/CaptureExceptionMiddleware/CaptureExceptionMiddlewareExtensions.cs @@ -2,6 +2,7 @@ namespace Vertical.Slice.Template.Shared.Web.ProblemDetail.Middlewares.CaptureExceptionMiddleware; +//https://github.com/dotnet/aspnetcore/pull/47760 public static class CaptureExceptionMiddlewareExtensions { public static IApplicationBuilder UseCaptureException(this IApplicationBuilder app) diff --git a/src/Vertical.Slice.Template/Products/ProductConfigurations.cs b/src/Vertical.Slice.Template/Products/ProductConfigurations.cs index 180cd96..c34cf8e 100644 --- a/src/Vertical.Slice.Template/Products/ProductConfigurations.cs +++ b/src/Vertical.Slice.Template/Products/ProductConfigurations.cs @@ -13,17 +13,17 @@ internal static class ProductConfigurations public const string Tag = "Products"; public const string ProductsPrefixUri = $"{CatalogsConfigurations.CatalogsPrefixUri}/products"; - public static WebApplicationBuilder AddProductsServices(this WebApplicationBuilder builder) + public static WebApplicationBuilder AddProductsModuleServices(this WebApplicationBuilder builder) { return builder; } - public static Task UseProducts(this WebApplication app) + public static Task UseProductsModule(this WebApplication app) { return Task.FromResult(app); } - public static IEndpointRouteBuilder MapProductsEndpoints(this IEndpointRouteBuilder endpoints) + public static IEndpointRouteBuilder MapProductsModuleEndpoints(this IEndpointRouteBuilder endpoints) { var products = endpoints.NewVersionedApi(Tag); var productsV1 = products.MapGroup(ProductsPrefixUri).HasDeprecatedApiVersion(0.9).HasApiVersion(1.0); diff --git a/src/Vertical.Slice.Template/Shared/CatalogsConfigurations.cs b/src/Vertical.Slice.Template/Shared/CatalogsConfigurations.cs index 643f28a..6a8061a 100644 --- a/src/Vertical.Slice.Template/Shared/CatalogsConfigurations.cs +++ b/src/Vertical.Slice.Template/Shared/CatalogsConfigurations.cs @@ -14,11 +14,15 @@ public static class CatalogsConfigurations public static WebApplicationBuilder AddCatalogsServices(this WebApplicationBuilder builder) { // Shared + // Infrastructure builder.AddInfrastructures(); + + // Shared + // Catalogs Configurations builder.AddStorage(); // Modules - builder.AddProductsServices(); + builder.AddProductsModuleServices(); return builder; } @@ -29,7 +33,7 @@ public static async Task UseCatalogs(this WebApplication app) await app.UseInfrastructure(); // Modules - await app.UseProducts(); + await app.UseProductsModule(); return app; } @@ -40,7 +44,7 @@ public static IEndpointRouteBuilder MapCatalogsEndpoints(this IEndpointRouteBuil endpoints.MapGet("/", () => "Catalogs Api.").ExcludeFromDescription(); // Modules - endpoints.MapProductsEndpoints(); + endpoints.MapProductsModuleEndpoints(); return endpoints; } diff --git a/src/Vertical.Slice.Template/Shared/Extensions/WebApplicationExtensions/WebApplicationExtensions.Infrastructure.cs b/src/Vertical.Slice.Template/Shared/Extensions/WebApplicationExtensions/WebApplicationExtensions.Infrastructure.cs index b52a3e6..09e38aa 100644 --- a/src/Vertical.Slice.Template/Shared/Extensions/WebApplicationExtensions/WebApplicationExtensions.Infrastructure.cs +++ b/src/Vertical.Slice.Template/Shared/Extensions/WebApplicationExtensions/WebApplicationExtensions.Infrastructure.cs @@ -25,6 +25,7 @@ public static Task UseInfrastructure(this WebApplication app) app.UseDeveloperExceptionPage(); // https://github.com/dotnet/aspnetcore/issues/4765 + // https://github.com/dotnet/aspnetcore/pull/47760 app.UseCaptureException(); }