| @@ -155,7 +155,13 @@ async def local_then_core(request: Request, call_next): | |||||
| local_resp = await call_next(request) # local storage runs here | local_resp = await call_next(request) # local storage runs here | ||||
| if local_resp.status_code >= 400: | if local_resp.status_code >= 400: | ||||
| return local_resp # stop if local failed | 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) | return await call_next(request) | ||||
| @app.exception_handler(NotAuthenticatedException) | @app.exception_handler(NotAuthenticatedException) | ||||
| @@ -165,6 +171,19 @@ def auth_exception_handler(request: Request, exc: NotAuthenticatedException): | |||||
| """ | """ | ||||
| return RedirectResponse(url='/login') | 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(auth_router) | ||||
| app.include_router(user_router) | app.include_router(user_router) | ||||
| #app.include_router(posts_router) | #app.include_router(posts_router) | ||||