diff --git a/utils/exceptions.py b/utils/exceptions.py index 18557ed..5c5e7e8 100644 --- a/utils/exceptions.py +++ b/utils/exceptions.py @@ -6,7 +6,10 @@ import traceback import threading import requests from rest_framework.views import exception_handler +from rest_framework.exceptions import AuthenticationFailed as DRFAuthenticationFailed +from rest_framework.exceptions import NotAuthenticated from rest_framework import status +from rest_framework_simplejwt.exceptions import InvalidToken, AuthenticationFailed as JWTAuthenticationFailed from utils.response import APIResponse @@ -136,8 +139,8 @@ class ErrorCode: def custom_exception_handler(exc, context): """自定义异常处理器""" - # 上报到 Log Center (仅上报非业务异常) - if not isinstance(exc, BusinessException): + # 上报到 Log Center (排除业务异常和认证异常,这些是正常业务流程) + if not isinstance(exc, (BusinessException, DRFAuthenticationFailed, NotAuthenticated, InvalidToken, JWTAuthenticationFailed)): report_to_log_center(exc, context) # 处理业务异常