This commit is contained in:
amb
2026-09-01 20:51:46 +08:00
parent 70ece67910
commit b80161972a
18 changed files with 1878 additions and 359 deletions
+13 -1
View File
@@ -114,12 +114,24 @@ async def app_error_handler(_: Request, exc: AppError) -> JSONResponse:
async def validation_error_handler(_: Request, exc: RequestValidationError) -> JSONResponse:
# 序列化错误详情,过滤不可 JSON 序列化的对象
errors = []
for err in exc.errors():
clean_err = {
"type": err.get("type", ""),
"loc": err.get("loc", []),
"msg": err.get("msg", ""),
}
if "input" in err:
clean_err["input"] = str(err["input"])
errors.append(clean_err)
return JSONResponse(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
content={
"code": "VALIDATION_ERROR",
"message": "请求参数不正确。",
"detail": exc.errors(),
"detail": errors,
},
)