From 0d437922c94ea6353b8df9fe43dfd08009d20ac3 Mon Sep 17 00:00:00 2001 From: OpenSquared Date: Sun, 19 Jul 2026 00:01:19 +0200 Subject: [PATCH] feat: strategy builder --- backend/main.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/backend/main.py b/backend/main.py index 4688640..0bfbbbe 100644 --- a/backend/main.py +++ b/backend/main.py @@ -68,6 +68,28 @@ app.add_middleware( ) +@app.exception_handler(Exception) +async def _global_exception_handler(request, exc: Exception): + """Catches anything that slips past a route's own try/except (including errors + during response serialization, which happen after a handler already returned) — + without this, such errors surface as an opaque bare "Internal Server Error" with + no detail and nothing in System Logs. Every unhandled exception, anywhere in the + app, now gets a full traceback in System Logs and a real JSON detail in the response.""" + import traceback + from fastapi.responses import JSONResponse + tb = traceback.format_exc() + try: + from services.database import log_system_event + log_system_event( + level="ERROR", source="unhandled_exception", + message=f"{request.method} {request.url.path}: {exc}", + details={"error": str(exc), "traceback": tb}, + ) + except Exception: + pass # Never let logging failure mask the original error + return JSONResponse(status_code=500, content={"detail": f"Erreur interne: {exc} (voir System Logs)"}) + + @app.on_event("startup") def startup(): # Attach DB log handler to root logger (captures WARNING+ from all modules)