From 942d68b75de203717eefeea36438a3337629c189 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Wed, 1 Jul 2026 12:31:24 -0500 Subject: [PATCH] debug: catch all exceptions and return traceback as JSON Co-Authored-By: Claude Sonnet 4.6 --- app/routes/debug_fb.py | 45 +++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/app/routes/debug_fb.py b/app/routes/debug_fb.py index 2a087ee..62c5af0 100644 --- a/app/routes/debug_fb.py +++ b/app/routes/debug_fb.py @@ -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()})