feat: 新增全局处理自定义登录异常
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from fastapi import FastAPI, Request
|
from fastapi import FastAPI, Request
|
||||||
from fastapi.exceptions import HTTPException
|
from fastapi.exceptions import HTTPException
|
||||||
from pydantic_validation_decorator import FieldValidationError
|
from pydantic_validation_decorator import FieldValidationError
|
||||||
from exceptions.exception import AuthException, PermissionException, ServiceException, ModelValidatorException
|
from exceptions.exception import AuthException, LoginException, PermissionException, ServiceException, ModelValidatorException
|
||||||
from utils.log_util import logger
|
from utils.log_util import logger
|
||||||
from utils.response_util import ResponseUtil, JSONResponse, jsonable_encoder
|
from utils.response_util import ResponseUtil, JSONResponse, jsonable_encoder
|
||||||
|
|
||||||
@@ -15,6 +15,11 @@ def handle_exception(app: FastAPI):
|
|||||||
async def auth_exception_handler(request: Request, exc: AuthException):
|
async def auth_exception_handler(request: Request, exc: AuthException):
|
||||||
return ResponseUtil.unauthorized(data=exc.data, msg=exc.message)
|
return ResponseUtil.unauthorized(data=exc.data, msg=exc.message)
|
||||||
|
|
||||||
|
# 自定义登录检验异常
|
||||||
|
@app.exception_handler(LoginException)
|
||||||
|
async def login_exception_handler(request: Request, exc: LoginException):
|
||||||
|
return ResponseUtil.failure(data=exc.data, msg=exc.message)
|
||||||
|
|
||||||
# 自定义权限检验异常
|
# 自定义权限检验异常
|
||||||
@app.exception_handler(PermissionException)
|
@app.exception_handler(PermissionException)
|
||||||
async def permission_exception_handler(request: Request, exc: PermissionException):
|
async def permission_exception_handler(request: Request, exc: PermissionException):
|
||||||
|
Reference in New Issue
Block a user