feat: 用户密码新增非法字符验证
This commit is contained in:
@@ -26,3 +26,13 @@ class PermissionException(Exception):
|
||||
def __init__(self, data: str = None, message: str = None):
|
||||
self.data = data
|
||||
self.message = message
|
||||
|
||||
|
||||
class ModelValidatorException(Exception):
|
||||
"""
|
||||
自定义模型校验异常ModelValidatorException
|
||||
"""
|
||||
|
||||
def __init__(self, data: str = None, message: str = None):
|
||||
self.data = data
|
||||
self.message = message
|
||||
|
@@ -1,6 +1,6 @@
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.exceptions import HTTPException
|
||||
from exceptions.exception import AuthException, PermissionException
|
||||
from exceptions.exception import AuthException, PermissionException, ModelValidatorException
|
||||
from utils.response_util import ResponseUtil, JSONResponse, jsonable_encoder
|
||||
|
||||
|
||||
@@ -18,6 +18,11 @@ def handle_exception(app: FastAPI):
|
||||
async def permission_exception_handler(request: Request, exc: PermissionException):
|
||||
return ResponseUtil.forbidden(data=exc.data, msg=exc.message)
|
||||
|
||||
# 自定义模型检验异常
|
||||
@app.exception_handler(ModelValidatorException)
|
||||
async def model_validator_exception_handler(request: Request, exc: ModelValidatorException):
|
||||
return ResponseUtil.failure(data=exc.data, msg=exc.message)
|
||||
|
||||
# 处理其他http请求异常
|
||||
@app.exception_handler(HTTPException)
|
||||
async def http_exception_handler(request: Request, exc: HTTPException):
|
||||
|
Reference in New Issue
Block a user