Implement global rate limiter and refactor auth middleware
- Add global rate limiter utility with configurable limits and cleanup - Move rate limiting logic to middleware for consistent application - Update auth routes to use new rate limiter - Add comprehensive tests for rate limiter functionality - Update documentation with backend development guidelines and tasks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -39,7 +39,6 @@ See Backend-Development.md for the complete exception contract.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Exception Base Classes (Categories)
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -107,6 +106,19 @@ class RateLimitError(DomainError):
|
||||
|
||||
error_code: str = "rate_limit_exceeded"
|
||||
|
||||
def __init__(self, message: str, retry_after_seconds: float = 60.0) -> None:
|
||||
"""Initialize with a message and optional retry-after time.
|
||||
|
||||
Args:
|
||||
message: Description of the rate limit violation.
|
||||
retry_after_seconds: Estimated seconds to wait before retrying (default 60).
|
||||
"""
|
||||
self.retry_after_seconds: float = retry_after_seconds
|
||||
super().__init__(message)
|
||||
|
||||
def get_error_metadata(self) -> dict[str, str | int | float | bool | None]:
|
||||
return {"retry_after_seconds": self.retry_after_seconds}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Jail-Specific Exceptions
|
||||
|
||||
Reference in New Issue
Block a user