debug: catch all exceptions and return traceback as JSON
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
bc5fc36a5d
commit
942d68b75d
+20
-25
@@ -1,3 +1,4 @@
|
||||
import traceback
|
||||
from fastapi import APIRouter, Request, Depends
|
||||
from fastapi.responses import JSONResponse
|
||||
from app.database import get_connection
|
||||
@@ -9,33 +10,27 @@ router = APIRouter(prefix="/debug-fb", tags=["debug"])
|
||||
|
||||
@router.get("/cups")
|
||||
async def find_cups(request: Request, user: dict = Depends(get_current_user)):
|
||||
conn = get_connection()
|
||||
cfg = {r["key"]: r["value"] for r in conn.execute("SELECT * FROM config").fetchall()}
|
||||
conn.close()
|
||||
try:
|
||||
conn = get_connection()
|
||||
cfg = {r["key"]: r["value"] for r in conn.execute("SELECT * FROM config").fetchall()}
|
||||
conn.close()
|
||||
|
||||
fb, ok, msg = get_firebird_from_config(cfg)
|
||||
if not ok:
|
||||
return JSONResponse({"error": msg})
|
||||
fb, ok, msg = get_firebird_from_config(cfg)
|
||||
if not ok:
|
||||
return JSONResponse({"error": msg})
|
||||
|
||||
results = {}
|
||||
results = {}
|
||||
|
||||
# Columnas de RELACION_HIMS
|
||||
ok1, err1, rows1 = fb.execute_query(
|
||||
"SELECT TRIM(f.RDB$FIELD_NAME) AS c FROM RDB$RELATION_FIELDS f "
|
||||
"WHERE TRIM(f.RDB$RELATION_NAME)='RELACION_HIMS' ORDER BY f.RDB$FIELD_POSITION"
|
||||
)
|
||||
results["columnas_relacion_hims"] = [r["c"] for r in rows1] if ok1 else f"error: {err1}"
|
||||
ok1, err1, rows1 = fb.execute_query(
|
||||
"SELECT FIRST 3 rh.* FROM RELACION_HIMS rh "
|
||||
"WHERE rh.CUPS_REF IS NOT NULL AND TRIM(rh.CUPS_REF)<>''"
|
||||
)
|
||||
results["relacion_hims_cups"] = list(rows1) if ok1 else f"error: {err1}"
|
||||
|
||||
# Muestra de RELACION_HIMS con CUPS_REF no vacío
|
||||
ok2, err2, rows2 = fb.execute_query(
|
||||
"SELECT FIRST 3 rh.* FROM RELACION_HIMS rh "
|
||||
"WHERE rh.CUPS_REF IS NOT NULL AND TRIM(rh.CUPS_REF) <> ''"
|
||||
)
|
||||
results["relacion_hims_con_cups"] = list(rows2) if (ok2 and rows2) else f"sin datos o error: {err2}"
|
||||
ok2, err2, rows2 = fb.execute_query("SELECT FIRST 1 rh.* FROM RELACION_HIMS rh")
|
||||
results["relacion_hims_fila"] = rows2[0] if (ok2 and rows2) else f"error: {err2}"
|
||||
|
||||
# Ver si RELACION_HIMS se conecta con RELACION (buscar campo IDRECEPCION o COD_EXAMEN)
|
||||
ok3, err3, rows3 = fb.execute_query("SELECT FIRST 1 rh.* FROM RELACION_HIMS rh")
|
||||
results["relacion_hims_primera_fila"] = rows3[0] if (ok3 and rows3) else f"error: {err3}"
|
||||
|
||||
fb.disconnect()
|
||||
return JSONResponse(results)
|
||||
fb.disconnect()
|
||||
return JSONResponse(results)
|
||||
except Exception:
|
||||
return JSONResponse({"traceback": traceback.format_exc()})
|
||||
|
||||
Reference in New Issue
Block a user