Refactor exception handling middleware
Updated DependencyInjection to use GlobalExceptionHandler. Removed ExceptionHandlingMiddleware and added GlobalExceptionHandlerMiddleware for unified exception handling across the application.
This commit is contained in:
parent
f93b197d45
commit
50c19fea31
@ -4,9 +4,9 @@ namespace DigitalData.Core.Exceptions;
|
||||
|
||||
public static class DependencyInjection
|
||||
{
|
||||
public static IApplicationBuilder UseExceptionHandlingMiddleware(this IApplicationBuilder app)
|
||||
public static IApplicationBuilder UseGlobalExceptionHandler(this IApplicationBuilder app)
|
||||
{
|
||||
app.UseMiddleware<ExceptionHandlingMiddleware>();
|
||||
app.UseMiddleware<GlobalExceptionHandlerMiddleware>();
|
||||
return app;
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,17 +10,17 @@ using System.Text.Json;
|
||||
/// Captures exceptions thrown during the request pipeline execution,
|
||||
/// logs them, and returns an appropriate HTTP response with a JSON error message.
|
||||
/// </summary>
|
||||
public class ExceptionHandlingMiddleware
|
||||
public class GlobalExceptionHandlerMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly ILogger<ExceptionHandlingMiddleware>? _logger;
|
||||
private readonly ILogger<GlobalExceptionHandlerMiddleware>? _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ExceptionHandlingMiddleware"/> class.
|
||||
/// Initializes a new instance of the <see cref="GlobalExceptionHandlerMiddleware"/> class.
|
||||
/// </summary>
|
||||
/// <param name="next">The next middleware in the request pipeline.</param>
|
||||
/// <param name="logger">The logger instance for logging exceptions.</param>
|
||||
public ExceptionHandlingMiddleware(RequestDelegate next, ILogger<ExceptionHandlingMiddleware>? logger = null)
|
||||
public GlobalExceptionHandlerMiddleware(RequestDelegate next, ILogger<GlobalExceptionHandlerMiddleware>? logger = null)
|
||||
{
|
||||
_next = next;
|
||||
_logger = logger;
|
||||
Loading…
x
Reference in New Issue
Block a user