Add global exception handling middleware to API
Introduced ExceptionHandlingMiddleware to catch and log unhandled exceptions, returning standardized JSON error responses. Registered the middleware in the request pipeline. Also made minor formatting and comment improvements in Program.cs and ICatalogRepository.cs.
This commit is contained in:
@@ -3,8 +3,9 @@ using DbFirst.Domain.Repositories;
|
||||
using DbFirst.Infrastructure;
|
||||
using DbFirst.Infrastructure.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DbFirst.API.Middleware;
|
||||
|
||||
//TODO: create and add exception handling middleware
|
||||
// TODO: create and add exception handling middleware - Done
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -43,6 +44,8 @@ if (app.Environment.IsDevelopment())
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseMiddleware<ExceptionHandlingMiddleware>();
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseCors();
|
||||
app.UseAuthorization();
|
||||
|
||||
Reference in New Issue
Block a user