Adding exception handler

This commit is contained in:
2023-12-13 22:22:29 +01:00
parent f1aad3344e
commit 39bac2a845

View File

@@ -1,5 +1,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
@@ -54,6 +56,17 @@ namespace WD7UVN_HFT_2023241.Endpoint
{
endpoints.MapControllers();
});
app.UseExceptionHandler(c => c.Run(async context =>
{
var exception = context.Features
.Get<IExceptionHandlerPathFeature>()
.Error;
var response = new { Msg = exception.Message };
await context.Response.WriteAsJsonAsync(response);
}));
}
}
}