@@ -15,11 +15,6 @@ public static class ServiceCollectionExceptionFiltersExtensions
1515{
1616 public static IServiceCollection AddExceptionMapper ( this IServiceCollection services , IConfiguration configuration , Action < IExceptionMappingBuilder > ? exceptionMappingBuilder = null )
1717 {
18- #if NET7_0_OR_GREATER
19- services . ConfigureHttpJsonOptions ( options => {
20- options . SerializerOptions . DictionaryKeyPolicy = options . SerializerOptions . PropertyNamingPolicy ;
21- } ) ;
22- #endif
2318 services . AddSingleton < ExceptionHandlerCollection > ( ) ;
2419 services . AddSingleton < ExceptionMapperOptions > ( ) ;
2520 services . TryAddSingleton < IExceptionHandlingManager , ExceptionHandlingManager > ( ) ;
@@ -36,8 +31,9 @@ public static IServiceCollection AddExceptionMapper(this IServiceCollection serv
3631 . Map < ResourceNotFoundException > ( ) . ToStatusCode ( StatusCodes . Status404NotFound )
3732 . Map < UnauthorizedException > ( ) . ToStatusCode ( StatusCodes . Status401Unauthorized )
3833
39- // ASP .NET Core exceptions
34+ // .NET exceptions
4035 . Map < BadHttpRequestException > ( ) . ToStatusCode ( StatusCodes . Status400BadRequest )
36+ . Map < NotImplementedException > ( ) . ToStatusCode ( StatusCodes . Status501NotImplemented )
4137
4238 // Common server exceptions
4339 . Map < GatewayTimeoutException > ( ) . ToStatusCode ( StatusCodes . Status504GatewayTimeout )
@@ -57,9 +53,14 @@ public static WebApplicationBuilder AddExceptionMapper(this WebApplicationBuilde
5753
5854 private static void AddSerializationHandler ( this IServiceCollection services , IConfiguration configuration )
5955 {
56+ #if NET7_0_OR_GREATER
57+ services . ConfigureHttpJsonOptions ( options => {
58+ options . SerializerOptions . DictionaryKeyPolicy = options . SerializerOptions . PropertyNamingPolicy ;
59+ } ) ;
60+ #endif
6061 services
6162 . AddOptions < ProblemDetailsSerializationOptions > ( )
62- . Bind ( configuration . GetSection ( "ExceptionFilters :ProblemDetailsSerialization" ) )
63+ . Bind ( configuration . GetSection ( "ExceptionMapper :ProblemDetailsSerialization" ) )
6364 . ValidateOnStart ( )
6465 ;
6566 services . AddSingleton ( sp => sp . GetRequiredService < IOptions < ProblemDetailsSerializationOptions > > ( ) . Value ) ;
@@ -77,7 +78,7 @@ private static void AddFallbackExceptionHandler(this IServiceCollection services
7778 {
7879 services
7980 . AddOptions < FallbackExceptionHandlerOptions > ( )
80- . Bind ( configuration . GetSection ( "ExceptionFilters :FallbackExceptionHandler" ) )
81+ . Bind ( configuration . GetSection ( "ExceptionMapper :FallbackExceptionHandler" ) )
8182 . ValidateOnStart ( )
8283 ;
8384 services . AddSingleton ( sp => sp . GetRequiredService < IOptions < FallbackExceptionHandlerOptions > > ( ) . Value ) ;
0 commit comments