Browse Source

feat: 新增FieldValidatorException全局异常处理

master
insistence 7 months ago
parent
commit
549948ba37
  1. 7
      ruoyi-fastapi-backend/exceptions/handle.py

7
ruoyi-fastapi-backend/exceptions/handle.py

@ -1,6 +1,6 @@
from fastapi import FastAPI, Request
from fastapi.exceptions import HTTPException
from exceptions.exception import AuthException, PermissionException, ModelValidatorException
from exceptions.exception import AuthException, PermissionException, ModelValidatorException, FieldValidatorException
from utils.response_util import ResponseUtil, JSONResponse, jsonable_encoder
@ -23,6 +23,11 @@ def handle_exception(app: FastAPI):
async def model_validator_exception_handler(request: Request, exc: ModelValidatorException):
return ResponseUtil.failure(data=exc.data, msg=exc.message)
# 自定义模型检验异常
@app.exception_handler(FieldValidatorException)
async def field_validator_exception_handler(request: Request, exc: FieldValidatorException):
return ResponseUtil.failure(data=exc.data, msg=exc.message)
# 处理其他http请求异常
@app.exception_handler(HTTPException)
async def http_exception_handler(request: Request, exc: HTTPException):

Loading…
Cancel
Save