-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors.py
More file actions
80 lines (57 loc) · 2.34 KB
/
errors.py
File metadata and controls
80 lines (57 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class Errors(Exception):
"""The base class for all library errors."""
def __init__(self, code=None, message: str | None = None):
self.code = code
self.message = message or ""
super().__init__(self.message)
def __str__(self) -> str:
return self.message or super().__str__()
class Forbidden(Errors):
"""Raised If you API key is invalid"""
def __init__(self, code, url, message):
self.url = url
super().__init__(code, message)
class TagNotFoundError(Errors):
"""Raised when a invalid player or club tag is passed"""
def __init__(self, code, **kwargs):
message = "An Invalid Tag has been passed!"
self.reason = kwargs.pop("reason", None)
self.invalid_characters = kwargs.pop("invalid_characters", [])
if self.reason:
message += "".join(f"\n Reason : {self.reason}")
elif self.invalid_characters:
message += "".join(f"\n Invalid characters : {self.invalid_characters}")
super().__init__(code, message)
class RateLimitError(Errors):
"""Raised when the rate limit is reached."""
def __init__(self, code, url):
self.url = url
super().__init__(code, "The rate limit has been reached.")
class UnexpectedError(Errors):
"""Raised if an unknown error has occured."""
def __init__(self, url, code, text):
self.url = url
super().__init__(code, f"An unexpected error has occured.\n{text}")
class ServerError(Errors):
"""Raised if the API is down."""
def __init__(self, code, url):
self.url = url
super().__init__(
code, "The API is down. Please be patient and try again later."
)
class BrawlerNotFound(Errors):
"""Raised when Invalid brawlerID has been passed"""
def __init__(self, code, id=None):
self.brawler_id = id
message = "Invalid ID passed!" if id is None else f"Invalid ID passed! {id}"
super().__init__(code, message)
class CountryNotFound(Errors):
"""Raised when Invalid countryCode has been passed"""
def __init__(self, code, countryCode=None):
self.country_code = countryCode
message = (
"Invalid countryCode passed!"
if countryCode is None
else f"Invalid countryCode passed! {countryCode}"
)
super().__init__(code, message)