|
|
@@ -0,0 +1,10 @@
|
|
|
+# exceptions.py
|
|
|
+
|
|
|
+from rest_framework.exceptions import NotAuthenticated
|
|
|
+from rest_framework.views import exception_handler
|
|
|
+from rest_framework.response import Response
|
|
|
+
|
|
|
+def custom_exception_handler(exc, context):
|
|
|
+ if isinstance(exc, NotAuthenticated):
|
|
|
+ return Response({'msg': '无认证信息或认证失败', "code": "403"}, status=403)
|
|
|
+ return exception_handler(exc, context) # 使用默认的异常处理器处理其他异常
|