diff --git a/DigitalData.Core.Exceptions.Middleware/DependencyInjection.cs b/DigitalData.Core.Exceptions.Middleware/DependencyInjection.cs index 945f18f..5c9ea6e 100644 --- a/DigitalData.Core.Exceptions.Middleware/DependencyInjection.cs +++ b/DigitalData.Core.Exceptions.Middleware/DependencyInjection.cs @@ -5,8 +5,16 @@ namespace DigitalData.Core.Exceptions.Middleware; public static class DependencyInjection { - public static IServiceCollection ConfigureGlobalExceptionHandler(this IServiceCollection services, Action options) + public static IServiceCollection ConfigureGlobalExceptionHandler(this IServiceCollection services, Action? options = null, bool addDefaultHandlers = true) { + options ??= opt => { }; + + if (addDefaultHandlers) + { + options += opt => opt.Add(HttpExceptionHandler.Default, setAsDefault: true); + options += opt => opt.Add(HttpExceptionHandler.DefaultBadRequest); + options += opt => opt.Add(HttpExceptionHandler.DefaultNotFound); + } return services.Configure(options); }