feat:对接中心平台,完善接口鉴权
This commit is contained in:
+13
-2
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user