feat:对接中心平台,完善接口鉴权

This commit is contained in:
2026-10-01 04:01:44 -07:00
parent 8e37d30ef2
commit 618290d852
20 changed files with 391 additions and 70 deletions
+13 -2
View File
@@ -16,14 +16,25 @@ from app.exceptions import AppError, DecisionError
class BizException(AppError):
"""可安全返回给调用方的业务错误"""
def __init__(self, code: int, msg: str = "请求失败") -> None:
def __init__(
self,
code: int,
msg: str = "请求失败",
headers: dict[str, str] | None = None,
) -> None:
self.code = code
self.msg = msg
# 协议响应头,例如 401 时的 WWW-Authenticate
self.headers = headers
super().__init__(msg)
async def handle_biz_exception(_request: Request, exc: BizException) -> JSONResponse:
return JSONResponse(status_code=exc.code, content=error_content(exc.code, exc.msg))
return JSONResponse(
status_code=exc.code,
content=error_content(exc.code, exc.msg),
headers=exc.headers,
)
async def handle_validation_exception(