Skip to content

Commit 8eb23ba

Browse files
committed
Map BadHttpRequestException to 400 Bad Request
1 parent fb22098 commit 8eb23ba

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/ForEvolve.ExceptionMapper/DependencyInjection/ServiceCollectionExtensions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ public static class ServiceCollectionExceptionFiltersExtensions
1515
{
1616
public static IServiceCollection AddExceptionMapper(this IServiceCollection services, IConfiguration configuration, Action<IExceptionMappingBuilder>? exceptionMappingBuilder = null)
1717
{
18-
//services.AddLogging();
18+
#if NET7_0_OR_GREATER
19+
services.ConfigureHttpJsonOptions(options => {
20+
options.SerializerOptions.DictionaryKeyPolicy = options.SerializerOptions.PropertyNamingPolicy;
21+
});
22+
#endif
1923
services.AddSingleton<ExceptionHandlerCollection>();
2024
services.AddSingleton<ExceptionMapperOptions>();
2125
services.TryAddSingleton<IExceptionHandlingManager, ExceptionHandlingManager>();
@@ -32,6 +36,9 @@ public static IServiceCollection AddExceptionMapper(this IServiceCollection serv
3236
.Map<ResourceNotFoundException>().ToStatusCode(StatusCodes.Status404NotFound)
3337
.Map<UnauthorizedException>().ToStatusCode(StatusCodes.Status401Unauthorized)
3438

39+
// ASP.NET Core exceptions
40+
.Map<BadHttpRequestException>().ToStatusCode(StatusCodes.Status400BadRequest)
41+
3542
// Common server exceptions
3643
.Map<GatewayTimeoutException>().ToStatusCode(StatusCodes.Status504GatewayTimeout)
3744
.Map<InternalServerErrorException>().ToStatusCode(StatusCodes.Status500InternalServerError)

0 commit comments

Comments
 (0)