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:
Developer 02 2025-05-16 15:59:38 +02:00
parent f93b197d45
commit 50c19fea31
2 changed files with 6 additions and 6 deletions

View File

@ -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;
}
}

View File

@ -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;