-
Notifications
You must be signed in to change notification settings - Fork 3
/
exceptions.py
43 lines (29 loc) · 1.08 KB
/
exceptions.py
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
import sys
class CustomError(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return self.message
class ApiKeyMissing(CustomError):
sys.tracebacklimit = 0
def __init__(self):
super().__init__("No token provided, please generate a token at https://csgoempire.com/trading/apikey")
class InvalidApiKey(CustomError):
sys.tracebacklimit = 0
def __init__(self):
super().__init__("Invalid token provided, please generate a token at https://csgoempire.com/trading/apikey")
class RequestError(CustomError):
pass
class InvalidDomain(CustomError):
sys.tracebacklimit = 0
pass
class ExceedsRatelimit(CustomError):
sys.tracebacklimit = 0
pass
def handle_error(status, response, class_name, function_name):
exception_mapping = {
401: InvalidApiKey,
429: ExceedsRatelimit
}
exception_class = exception_mapping.get(status, RequestError)
raise exception_class(f"{class_name}:{function_name}:{status}: {response['message']}")