author_error.py 444 B

12345678910
  1. # exceptions.py
  2. from rest_framework.exceptions import NotAuthenticated
  3. from rest_framework.views import exception_handler
  4. from rest_framework.response import Response
  5. def custom_exception_handler(exc, context):
  6. if isinstance(exc, NotAuthenticated):
  7. return Response({'msg': '无认证信息或认证失败', "code": "403"}, status=403)
  8. return exception_handler(exc, context) # 使用默认的异常处理器处理其他异常