Files
lotteryServer/exceptions/handlers.py
2026-09-07 13:24:09 +08:00

25 lines
590 B
Python

from fastapi import Request, FastAPI
from fastapi.responses import JSONResponse
from exceptions.errors import AgentNotReadyError
async def agent_not_ready_handler(request: Request, exc: Exception):
"""agent未就绪的错误"""
return JSONResponse(
status_code=503,
content={
"code": 503,
"message": str(exc)
}
)
# 集中处理 保持main简洁
def register_exception_handlers(app: FastAPI):
"""集中处理注册异常"""
app.add_exception_handler(
AgentNotReadyError,
agent_not_ready_handler,
)