1# pylint: disable=C0114,C0115
2from typing import Any
3from typing import Dict
4from typing import TYPE_CHECKING
5from typing import Union
6
7
8if TYPE_CHECKING:
9 from .request_rate import RequestRate
10
11
12class BucketFullException(Exception):
13 def __init__(self, identity: str, rate: "RequestRate", remaining_time: float):
14 error = f"Bucket for {identity} with Rate {rate} is already full"
15 self.meta_info: Dict[str, Union[str, float]] = {
16 "error": error,
17 "identity": identity,
18 "rate": str(rate),
19 "remaining_time": remaining_time,
20 }
21 super().__init__(error)
22
23
24class InvalidParams(Exception):
25 def __init__(self, param_name: str):
26 self.message = f"Parameters missing or invalid:{param_name}"
27 super().__init__(self.message)
28
29
30class ImmutableClassProperty(Exception):
31 def __init__(self, class_instance: Any, prop: str):
32 """Mutating class property is forbidden"""
33 self.message = f"{class_instance}.{prop} must not be mutated"
34 super().__init__(self.message)