Add global exception handling middleware

Introduce `ExceptionHandlingMiddleware` to capture and log exceptions globally in the application. This middleware returns appropriate JSON error responses based on specific exception types, such as `BadRequestException` and `NotFoundException`. The middleware is registered in `Program.cs` to ensure it processes all HTTP requests.
This commit is contained in:
Developer 02
2025-05-09 10:11:28 +02:00
parent 3fce092486
commit 4ee5250b01
2 changed files with 93 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ using EnvelopeGenerator.GeneratorAPI.Models;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using DigitalData.Core.Abstractions.Security.Extensions;
using EnvelopeGenerator.GeneratorAPI.Middleware;
var builder = WebApplication.CreateBuilder(args);
@@ -169,6 +170,8 @@ var app = builder.Build();
deferredProvider.Factory = () => app.Services;
app.UseMiddleware<ExceptionHandlingMiddleware>();
app.MapOpenApi();
// Configure the HTTP request pipeline.