chef_agent
This commit is contained in:
0
exceptions/__init__.py
Normal file
0
exceptions/__init__.py
Normal file
3
exceptions/errors.py
Normal file
3
exceptions/errors.py
Normal file
@@ -0,0 +1,3 @@
|
||||
class AgentNotReadyError(RuntimeError):
|
||||
"""agent未初始化错误"""
|
||||
pass
|
||||
24
exceptions/handlers.py
Normal file
24
exceptions/handlers.py
Normal 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,
|
||||
)
|
||||
Reference in New Issue
Block a user