Fix silent exception swallowing in route handlers #11

Open
opened 2026-04-20 09:35:44 +00:00 by sharang · 0 comments
Owner

Problem

Multiple route handlers catch broad exceptions and return empty responses, making outages invisible:

# compliance/api/crosswalk_routes.py
except Exception:
    return {}
finally:
    db.close()

When the database is down or a query fails, the client receives {} with HTTP 200. No error is logged. Monitoring cannot detect the failure.

Required Actions

  1. Grep for except Exception across all compliance/api/ files — audit each occurrence
  2. For each: log the full exception with logger.exception("...", exc_info=True) before handling
  3. Re-raise as HTTPException(status_code=500) with a generic client message (never raw str(e))
  4. Replace bare return {} with raise HTTPException(500, detail="Internal error")
  5. Add a global FastAPI exception handler in main.py as a final safety net

Acceptance Criteria

  • grep -r "except Exception:" compliance/api/ — every match has a logger.exception call before it
  • A simulated DB failure returns HTTP 500, not HTTP 200 with empty body
  • Errors appear in structured logs with request context
## Problem Multiple route handlers catch broad exceptions and return empty responses, making outages invisible: ```python # compliance/api/crosswalk_routes.py except Exception: return {} finally: db.close() ``` When the database is down or a query fails, the client receives `{}` with HTTP 200. No error is logged. Monitoring cannot detect the failure. ## Required Actions 1. Grep for `except Exception` across all `compliance/api/` files — audit each occurrence 2. For each: log the full exception with `logger.exception("...", exc_info=True)` before handling 3. Re-raise as `HTTPException(status_code=500)` with a generic client message (never raw `str(e)`) 4. Replace bare `return {}` with `raise HTTPException(500, detail="Internal error")` 5. Add a global FastAPI exception handler in `main.py` as a final safety net ## Acceptance Criteria - `grep -r "except Exception:" compliance/api/` — every match has a `logger.exception` call before it - A simulated DB failure returns HTTP 500, not HTTP 200 with empty body - Errors appear in structured logs with request context
sharang added this to the M2: Data Integrity & Reliability milestone 2026-04-20 09:35:44 +00:00
sharang added the observabilityreliabilityseverity: high labels 2026-04-20 09:35:44 +00:00
Sign in to join this conversation.