feat: strategy builder
This commit is contained in:
@@ -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")
|
@app.on_event("startup")
|
||||||
def startup():
|
def startup():
|
||||||
# Attach DB log handler to root logger (captures WARNING+ from all modules)
|
# Attach DB log handler to root logger (captures WARNING+ from all modules)
|
||||||
|
|||||||
Reference in New Issue
Block a user