Enhance ConfigureGlobalExceptionHandler method
Updated the `ConfigureGlobalExceptionHandler` method in the `DependencyInjection` class to include two optional parameters: `options` (nullable) and `addDefaultHandlers` (defaulting to true). The method now initializes `options` to a default action if null and adds default exception handlers when `addDefaultHandlers` is true, improving flexibility and usability.
This commit is contained in:
parent
fd8e976e1e
commit
87e4c1414e
@ -5,8 +5,16 @@ namespace DigitalData.Core.Exceptions.Middleware;
|
|||||||
|
|
||||||
public static class DependencyInjection
|
public static class DependencyInjection
|
||||||
{
|
{
|
||||||
public static IServiceCollection ConfigureGlobalExceptionHandler(this IServiceCollection services, Action<GlobalExceptionHandlerOptions> options)
|
public static IServiceCollection ConfigureGlobalExceptionHandler(this IServiceCollection services, Action<GlobalExceptionHandlerOptions>? 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);
|
return services.Configure(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user