namespace Sonex.Services.WebApi.EndPoints; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Npgsql; using Sonex.Data.Records; public static class ClientErrorLogEndpoints { public static void MapClientErrorLogEndpoints(this WebApplication app) { app.MapPost("/api/client-errors", async (AppLoggerRecord model) => { try { var result = await AppLoggerRecord.Create(model); if (!result.Success) { return Results.BadRequest(new { error = result.ErrorMessage }); } return Results.Ok(new { accepted = true, errorId = model.ErrorId }); } catch (PostgresException ex) when (ex.SqlState == PostgresErrorCodes.UniqueViolation) { return Results.Conflict(new { error = $"Log with ErrorId '{model.ErrorId}' already exists." }); } catch (Exception ex) { return Results.Problem( title: "Failed to save client error log.", detail: ex.Message, statusCode: StatusCodes.Status500InternalServerError); } }); } }