feat:简化部分代码
This commit is contained in:
+5
-13
@@ -10,7 +10,7 @@ from openai import APIError, APITimeoutError
|
||||
from starlette.exceptions import HTTPException
|
||||
|
||||
from app.common.response import error_content
|
||||
from app.exceptions import AppError, DecisionError, ImportProcessError
|
||||
from app.exceptions import AppError, DecisionError
|
||||
|
||||
|
||||
class BizException(AppError):
|
||||
@@ -58,22 +58,14 @@ async def handle_unexpected_exception(
|
||||
|
||||
exc._logged_by_api = True
|
||||
|
||||
# 节点包装异常时沿原始原因查找,区分上游服务故障与内部错误
|
||||
cause = exc
|
||||
while isinstance(cause, ImportProcessError):
|
||||
nested = cause.cause or cause.__cause__
|
||||
if nested is None:
|
||||
break
|
||||
cause = nested
|
||||
if isinstance(cause, APITimeoutError) or (
|
||||
isinstance(cause, DecisionError) and cause.kind == "timeout"
|
||||
if isinstance(exc, APITimeoutError) or (
|
||||
isinstance(exc, DecisionError) and exc.kind == "timeout"
|
||||
):
|
||||
return JSONResponse(
|
||||
status_code=504, content=error_content(504, "模型服务请求超时")
|
||||
)
|
||||
if isinstance(cause, APIError) or (
|
||||
isinstance(cause, DecisionError)
|
||||
and cause.kind not in {"configuration", "closed"}
|
||||
if isinstance(exc, APIError) or (
|
||||
isinstance(exc, DecisionError) and exc.kind != "configuration"
|
||||
):
|
||||
return JSONResponse(
|
||||
status_code=502, content=error_content(502, "模型服务调用失败")
|
||||
|
||||
Reference in New Issue
Block a user