Import Statement
All public exceptions can be imported directly from the main package:Exception Hierarchy
All exceptions inherit from the baseRateLimiterError, which itself inherits from Python’s built-in Exception.
Public Exceptions
These exceptions are exported in__all__ and are part of the public API.
RateLimiterError
The base class for all exceptions in the library. Catching this will catch any error raised by the rate limiter.
CapacityExceededError
Raised when a request cannot be fulfilled because the rate limit has been exceeded and the scheduler cannot queue it (e.g., queue full or immediate rejection policy).
Constructor:
bucket_id(Optional[str]): The ID of the bucket that is rate limited.retry_after(Optional[float]): Suggested wait time in seconds before retrying.
BucketNotFoundError
Raised when attempting to access a rate limit bucket that does not exist and cannot be automatically created.
Constructor:
"Rate limit bucket not found: {bucket_id}"
Attributes:
bucket_id(str): The ID of the bucket that was not found.
ReservationCapacityError
Raised when the internal ReservationTracker is full. This usually indicates a massive backlog of uncompleted requests or a memory leak in reservation cleanup.
BackendConnectionError
Raised when the backend (e.g., Redis) cannot be reached. Handle this to implement connection retry logic or fallback behavior.
BackendOperationError
Raised when a backend operation fails (e.g., Redis command error, serialization failure).
ConfigurationError
Raised when the RateLimiterConfig or StateConfig is invalid. Typically raised during scheduler initialization.
QueueOverflowError
Raised when the internal request queue for a bucket is full. This exception can be caught to implement custom queue overflow handling.
Constructor:
queue_key(Optional[str]): The key identifying which queue overflowed.
TooManyFailedRequestsError
Raised when too many requests have failed within a time window. This is a circuit-breaker mechanism to prevent cascading failures when the upstream service is degraded.
Constructor:
failure_count(Optional[int]): The number of failed requests in the current window.window_seconds(Optional[float]): The time window in seconds over which failures are tracked.threshold(Optional[int]): The failure threshold that was exceeded.