소스 검색

fix errorlog bug where core errors are proxyed to the core and every 500 error returned the log in the body

errorlogbug
Lorenzo Pollutri 1 개월 전
부모
커밋
0bfd600c3d
1개의 변경된 파일20개의 추가작업 그리고 1개의 파일을 삭제
  1. +20
    -1
      app.py

+ 20
- 1
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)


불러오는 중...
취소
저장