fix(backend): log create_slab driver errors server-side
QUALITY-120 keeps the driver stack out of the owner-facing response, but the bare except logged nothing, so a failing create was undiagnosable in the field. Log the exception server-side while keeping the generic owner message.
This commit is contained in:
+7
-2
@@ -6,6 +6,7 @@ sets deleted_at; published slabs cannot be deleted.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
@@ -15,6 +16,8 @@ from fastapi.responses import JSONResponse, Response
|
|||||||
from .db import get_connection
|
from .db import get_connection
|
||||||
from .thickness_band import load_thickness_terms, resolve_thickness_band_id
|
from .thickness_band import load_thickness_terms, resolve_thickness_band_id
|
||||||
|
|
||||||
|
logger = logging.getLogger("slab.backend")
|
||||||
|
|
||||||
router = APIRouter(prefix="/api/v1/slabs")
|
router = APIRouter(prefix="/api/v1/slabs")
|
||||||
|
|
||||||
# Client-settable slab columns (explicit allowlist; never build SQL from client keys).
|
# Client-settable slab columns (explicit allowlist; never build SQL from client keys).
|
||||||
@@ -224,8 +227,10 @@ async def create_slab(payload: Dict[str, Any]) -> Dict[str, Any]:
|
|||||||
try:
|
try:
|
||||||
conn.execute(f"INSERT INTO slabs ({', '.join(cols)}) VALUES ({ph})", vals)
|
conn.execute(f"INSERT INTO slabs ({', '.join(cols)}) VALUES ({ph})", vals)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
except Exception:
|
except Exception as exc:
|
||||||
# QUALITY-120: never surface a driver stack to the owner.
|
# QUALITY-120: never surface a driver stack to the owner, but log it
|
||||||
|
# server-side so a failing create is diagnosable.
|
||||||
|
logger.error("create_slab insert failed: %s", exc, exc_info=True)
|
||||||
return _err("validation", "Could not create the slab. Check the fields and try again.", status=400)
|
return _err("validation", "Could not create the slab. Check the fields and try again.", status=400)
|
||||||
row = conn.execute("SELECT * FROM slabs WHERE id=?", (payload["id"],)).fetchone()
|
row = conn.execute("SELECT * FROM slabs WHERE id=?", (payload["id"],)).fetchone()
|
||||||
return _row_to_slab(row)
|
return _row_to_slab(row)
|
||||||
|
|||||||
Reference in New Issue
Block a user