mirror of
https://github.com/suitenumerique/meet.git
synced 2026-09-09 08:55:42 +00:00
fixup! 🔇(backend) silence expected 401 warnings on /me
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class SilenceExpected401(logging.Filter):
|
||||
"""Drop the expected 401 from anonymous hits on the /me endpoint.
|
||||
@@ -11,11 +13,13 @@ class SilenceExpected401(logging.Filter):
|
||||
"""
|
||||
|
||||
def filter(self, record):
|
||||
"""Return False for a 401 on `/users/me`."""
|
||||
if getattr(record, "status_code", None) == 401:
|
||||
request = getattr(record, "request", None)
|
||||
path = getattr(request, "path", "") or ""
|
||||
if path.rstrip("/").endswith("/users/me"):
|
||||
return False
|
||||
"""Return False for a 401 on a silenced path, True otherwise."""
|
||||
if getattr(record, "status_code", None) != 401:
|
||||
return True
|
||||
|
||||
return True
|
||||
request = getattr(record, "request", None)
|
||||
path = getattr(request, "path", None)
|
||||
if not path:
|
||||
return True
|
||||
|
||||
return path not in settings.LOGGING_SILENCED_401_PATHS
|
||||
|
||||
@@ -1110,6 +1110,12 @@ class Base(Configuration):
|
||||
environ_prefix=None,
|
||||
)
|
||||
|
||||
LOGGING_SILENCED_401_PATHS = values.ListValue(
|
||||
default=["/api/v1.0/users/me/"],
|
||||
environ_name="LOGGING_SILENCED_401_PATHS",
|
||||
environ_prefix=None,
|
||||
)
|
||||
|
||||
# Logging
|
||||
# We want to make it easy to log to console but by default we log production
|
||||
# to Sentry and don't want to log to console.
|
||||
|
||||
Reference in New Issue
Block a user