found auth bug in middleware if token on client expires it will send 500 error versus 401.
from django.conf import settings
+from rest_framework.exceptions import AuthenticationFailed
import threading
request_local = threading.local()
-
def get_username():
return getattr(request_local, "username", None)
@@ -50,6 +50,7 @@ class AuditMiddleware:
request = APIView().initialize_request(request)
# check if user is authenticated
+ try:
if hasattr(request, "user") and request.user.is_authenticated:
debug_info = {}
@@ -63,8 +64,10 @@ class AuditMiddleware:
request_local.debug_info = debug_info
- # get authentcated user after request
+ # get authenticated user after request
request_local.username = request.user.username
+ except AuthenticationFailed:
+ pass
def process_exception(self, request, exception):
request_local.debug_info = None
