From 0bfd600c3d361b1827f80c871e7f4a4a46e46965 Mon Sep 17 00:00:00 2001 From: pollutri Date: Thu, 12 Feb 2026 17:12:49 +0100 Subject: [PATCH] fix errorlog bug where core errors are proxyed to the core and every 500 error returned the log in the body --- app.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index e77b806..93000a5 100644 --- a/app.py +++ b/app.py @@ -155,7 +155,13 @@ async def local_then_core(request: Request, call_next): local_resp = await call_next(request) # local storage runs here if local_resp.status_code >= 400: return local_resp # stop if local failed - return await _forward_to_core(request, body) + try: + core_resp = await _forward_to_core(request, body) + except httpx.RequestError: + return local_resp + if core_resp.status_code >= 400: + return local_resp + return core_resp return await call_next(request) @app.exception_handler(NotAuthenticatedException) @@ -165,6 +171,19 @@ def auth_exception_handler(request: Request, exc: NotAuthenticatedException): """ return RedirectResponse(url='/login') +# Nasconde i dettagli degli errori 5xx +@app.exception_handler(HTTPException) +async def http_exception_handler(request: Request, exc: HTTPException): + if exc.status_code >= 500: + log.exception("HTTP %s: %s", exc.status_code, exc.detail) + return JSONResponse(status_code=exc.status_code, content={"detail": "Internal Server Error"}) + return JSONResponse(status_code=exc.status_code, content={"detail": exc.detail}) + +@app.exception_handler(Exception) +async def unhandled_exception_handler(request: Request, exc: Exception): + log.exception("Unhandled exception") + return JSONResponse(status_code=500, content={"detail": "Internal Server Error"}) + app.include_router(auth_router) app.include_router(user_router) #app.include_router(posts_router)