Standardize service errors with ProblemDetails envelope
This commit is contained in:
@@ -3,6 +3,7 @@ using GameList.Domain;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace GameList.Infrastructure;
|
||||
|
||||
@@ -44,7 +45,14 @@ public static class PlayerIdentityExtensions
|
||||
|
||||
context.Response.StatusCode = StatusCodes.Status500InternalServerError;
|
||||
context.Response.ContentType = "application/json";
|
||||
await context.Response.WriteAsJsonAsync(new { error = "Unexpected server error" });
|
||||
var problem = new ProblemDetails
|
||||
{
|
||||
Status = StatusCodes.Status500InternalServerError,
|
||||
Title = "Internal Server Error",
|
||||
Detail = "Unexpected server error"
|
||||
};
|
||||
problem.Extensions["error"] = "Unexpected server error";
|
||||
await context.Response.WriteAsJsonAsync(problem);
|
||||
});
|
||||
});
|
||||
return app;
|
||||
|
||||
Reference in New Issue
Block a user