Merged in feature/mutable-metadata1 (pull request #221)

M1, M2 and M3 complete

* M1, M2 and M3 complete

* review changes

* docs

* docs
This commit is contained in:
Jay Brown
2026-04-16 23:11:26 +00:00
parent ad7b21f3a2
commit 17fc813823
164 changed files with 44700 additions and 371 deletions
+20
View File
@@ -1,6 +1,7 @@
package queryapi
import (
"errors"
"fmt"
"log/slog"
"net/http"
@@ -10,6 +11,7 @@ import (
"queryorchestration/internal/fieldextraction"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgtype"
"github.com/labstack/echo/v4"
openapi_types "github.com/oapi-codegen/runtime/types"
@@ -45,6 +47,24 @@ func (s *Controllers) CreateFieldExtraction(ctx echo.Context) error {
// Create field extraction via service
extraction, err := s.svc.FieldExtraction.CreateFieldExtraction(ctx.Request().Context(), input)
if err != nil {
// Milestone 2.5: map the new typed sentinels from the service
// layer plus the Postgres check_violation (Trigger 2 backstop)
// onto clean HTTP status codes before falling through to 500.
if errors.Is(err, fieldextraction.ErrDocumentNotFound) {
return echo.NewHTTPError(http.StatusNotFound, "document not found")
}
if errors.Is(err, fieldextraction.ErrMutualExclusivityViolation) {
return echo.NewHTTPError(http.StatusConflict,
"document is bound to a custom schema and cannot accept legacy field extractions")
}
var pgErr *pgconn.PgError
if errors.As(err, &pgErr) && pgErr.Code == "23514" {
// Trigger 2 fired. Defense in depth — service-layer guard
// already should have caught this, but if the lock path
// was bypassed (regression) the DB enforces the same 409.
return echo.NewHTTPError(http.StatusConflict,
"document is bound to a custom schema and cannot accept legacy field extractions")
}
slog.Error("failed to create field extraction", "error", err, "document_id", documentID)
return echo.NewHTTPError(http.StatusInternalServerError, "failed to create field extraction")
}