chef_agent

This commit is contained in:
2026-09-07 13:24:09 +08:00
parent 86ece1926d
commit bc44de93bc
14 changed files with 133 additions and 63 deletions

0
exceptions/__init__.py Normal file
View File

3
exceptions/errors.py Normal file
View File

@@ -0,0 +1,3 @@
class AgentNotReadyError(RuntimeError):
"""agent未初始化错误"""
pass

24
exceptions/handlers.py Normal file
View File

@@ -0,0 +1,24 @@
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,
)