-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors.py
More file actions
87 lines (62 loc) · 2.43 KB
/
errors.py
File metadata and controls
87 lines (62 loc) · 2.43 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
81
82
83
84
85
86
87
class Errors(Exception):
"""The Base Class for all errors"""
def __init__(self, code, message):
pass
def __str__(self):
return self.message
class Forbidden(Errors):
"""Raised If you API key is invalid"""
def __init__(self, code, url, message):
self.code = code
self.url = url
self.message = message
super().__init__(self.code, self.message)
class TagNotFoundError(Errors):
"""Raised when a invalid player or club tag is passed"""
def __init__(self, code, **kwargs):
self.code = code
self.message = "An Invalid Tag has been passed!"
self.reason = kwargs.pop("reason", None)
self.invalid_characters = kwargs.pop("invalid_characters", [])
if self.reason:
self.message += "".join(f"\n Reason : {self.reason}")
elif self.invalid_characters:
self.message += "".join(
f"\n Invalid characters : {self.invalid_characters}"
)
super().__init__(self.code, self.message)
class RateLimitError(Errors):
"""Raised when the rate limit is reached."""
def __init__(self, code, url):
self.code = code
self.url = url
self.message = "The rate limit has been reached."
super().__init__(self.code, self.message)
class UnexpectedError(Errors):
"""Raised if an unknown error has occured."""
def __init__(self, url, code, text):
self.code = code
self.url = url
self.message = f"An unexpected error has occured.\n{text}"
super().__init__(self.code, self.message)
class ServerError(Errors):
"""Raised if the API is down."""
def __init__(self, code, url):
self.code = code
self.url = url
self.message = "The API is down. Please be patient and try again later."
super().__init__(self.code, self.message)
class BrawlerNotFound(Errors):
"""Raised when Invalid brawlerID has been passed"""
def __init__(self, code, id=None):
self.code = code
if id:
self.message = "Invalid ID passed! {}".format(id)
super().__init__(self.code, self.message)
class CountryNotFound(Errors):
"""Raised when Invalid countryCode has been passed"""
def __init__(self, code, countryCode=None):
self.code = code
if id:
self.message = "Invalid countryCode passed! {}".format(countryCode)
super().__init__(self.code, self.message)