管理端后端
This commit is contained in:
1 parent
eebc5518c5
commit
4ef6f6c90d
24 files changed
+1745
-10
No files matched your search
@@ -8,12 +8,18 @@ public sealed class GlobalExceptionHandler(ILogger<GlobalExceptionHandler> logge
|
||||
public async ValueTask<bool> TryHandleAsync(HttpContext httpContext, Exception exception, CancellationToken cancellationToken)
|
||||
{
|
||||
var traceId = httpContext.TraceIdentifier;
|
||||
logger.LogError(exception, "Unhandled request failure. TraceId: {TraceId}", traceId);
|
||||
var status = exception switch
|
||||
{
|
||||
UnauthorizedAccessException => StatusCodes.Status403Forbidden,
|
||||
InvalidOperationException => StatusCodes.Status409Conflict,
|
||||
_ => StatusCodes.Status500InternalServerError
|
||||
};
|
||||
if (status >= 500) logger.LogError(exception, "Unhandled request failure. TraceId: {TraceId}", traceId);
|
||||
var problem = new ProblemDetails
|
||||
{
|
||||
Status = StatusCodes.Status500InternalServerError,
|
||||
Title = "An unexpected error occurred.",
|
||||
Type = "https://tools.ietf.org/html/rfc9110#section-15.6.1",
|
||||
Status = status,
|
||||
Title = status == StatusCodes.Status403Forbidden ? "The action is outside your authorized scope." : status == StatusCodes.Status409Conflict ? "The request conflicts with current data or workflow state." : "An unexpected error occurred.",
|
||||
Type = status == StatusCodes.Status403Forbidden ? "https://tools.ietf.org/html/rfc9110#section-15.5.4" : "https://tools.ietf.org/html/rfc9110#section-15.6.1",
|
||||
Instance = httpContext.Request.Path
|
||||
};
|
||||
problem.Extensions["traceId"] = traceId;
|
||||
|
||||
Reference in new issue
Block a user