feat: add catalog readonly endpoints

This commit is contained in:
xiong
2026-07-26 14:02:04 +08:00
parent 41a8a5ff81
commit d5379affba
10 changed files with 962 additions and 53 deletions

View File

@@ -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