Add phase-aware frontend shell, polling client, and global exception handler
This commit is contained in:
18
Program.cs
18
Program.cs
@@ -1,5 +1,6 @@
|
||||
using GameList.Data;
|
||||
using GameList.Domain;
|
||||
using Microsoft.AspNetCore.Diagnostics;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Data.Sqlite;
|
||||
@@ -46,6 +47,23 @@ builder.Services.ConfigureHttpJsonOptions(options =>
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseExceptionHandler(handler =>
|
||||
{
|
||||
handler.Run(async context =>
|
||||
{
|
||||
var feature = context.Features.Get<IExceptionHandlerFeature>();
|
||||
var logger = context.RequestServices.GetRequiredService<ILoggerFactory>().CreateLogger("GlobalException");
|
||||
if (feature?.Error != null)
|
||||
{
|
||||
logger.LogError(feature.Error, "Unhandled exception");
|
||||
}
|
||||
|
||||
context.Response.StatusCode = StatusCodes.Status500InternalServerError;
|
||||
context.Response.ContentType = "application/json";
|
||||
await context.Response.WriteAsJsonAsync(new { error = "Unexpected server error" });
|
||||
});
|
||||
});
|
||||
|
||||
// Ensure database and migrations are applied on startup
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user