forked from xiongyuxing/tiku-backend.net
feat: add catalog readonly endpoints
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Tiku.Api.Controllers;
|
||||
using Tiku.Application.Auth;
|
||||
|
||||
namespace Tiku.Api.Middleware;
|
||||
@@ -22,6 +23,16 @@ public sealed class ExceptionHandlingMiddleware(
|
||||
return;
|
||||
}
|
||||
|
||||
if (exception is TenantNotFoundException)
|
||||
{
|
||||
await WriteProblemAsync(
|
||||
context,
|
||||
"Tenant was not found.",
|
||||
StatusCodes.Status404NotFound,
|
||||
"tenant_not_found");
|
||||
return;
|
||||
}
|
||||
|
||||
logger.LogError(exception, "Unhandled API exception");
|
||||
|
||||
var problem = new ProblemDetails
|
||||
@@ -38,6 +49,25 @@ public sealed class ExceptionHandlingMiddleware(
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task WriteProblemAsync(
|
||||
HttpContext context,
|
||||
string title,
|
||||
int status,
|
||||
string code)
|
||||
{
|
||||
var problem = new ProblemDetails
|
||||
{
|
||||
Title = title,
|
||||
Status = status,
|
||||
Instance = context.Request.Path
|
||||
};
|
||||
|
||||
problem.Extensions["code"] = code;
|
||||
problem.Extensions["traceId"] = context.TraceIdentifier;
|
||||
context.Response.StatusCode = status;
|
||||
await context.Response.WriteAsJsonAsync(problem);
|
||||
}
|
||||
|
||||
private static async Task WriteAuthProblemAsync(HttpContext context, AuthException exception)
|
||||
{
|
||||
var status = exception.Code switch
|
||||
|
||||
Reference in New Issue
Block a user