diff --git a/src/aare/common/exception_handler.py b/src/aare/common/exception_handler.py index 7098c362..9a84f6f2 100644 --- a/src/aare/common/exception_handler.py +++ b/src/aare/common/exception_handler.py @@ -104,6 +104,8 @@ class AuthenticationException(Exception): class UserRightsException(Exception): + _last_log_ts_by_message: dict[str, float] = {} + _throttle_window_s = 30.0 def __init__(self, message: str = "User does not have rights to perform this action.", *, @@ -115,7 +117,12 @@ class UserRightsException(Exception): self.status_code = status_code self.headers = headers self.code = code - logger.error(message, extra={"exception:": Exception}) + + now = time.monotonic() + last_ts = self._last_log_ts_by_message.get(message, 0.0) + if (now - last_ts) >= self._throttle_window_s: + self._last_log_ts_by_message[message] = now + logger.warning(message, extra={"exception:": Exception}) def __str__(self) -> str: return self.message