forked from GetStream/stream-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexceptions.py
More file actions
90 lines (62 loc) · 1.82 KB
/
exceptions.py
File metadata and controls
90 lines (62 loc) · 1.82 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
88
89
90
class StreamApiException(Exception):
def __init__(self, error_message, status_code=None):
Exception.__init__(self, error_message)
self.detail = error_message
if status_code is not None:
self.status_code = status_code
code = 1
def __repr__(self):
return '%s (%s)' % (self.__class__.__name__, self.detail)
def __unicode__(self):
return '%s (%s)' % (self.__class__.__name__, self.detail)
class ApiKeyException(StreamApiException):
'''
Raised when there is an issue with your Access Key
'''
status_code = 401
code = 2
class SignatureException(StreamApiException):
'''
Raised when there is an issue with the signature you provided
'''
status_code = 401
code = 3
class InputException(StreamApiException):
'''
Raised when you send the wrong data to the API
'''
status_code = 400
code = 4
class CustomFieldException(StreamApiException):
'''
Raised when there are missing or misconfigured custom fields
'''
status_code = 400
code = 5
class FeedConfigException(StreamApiException):
'''
Raised when there are missing or misconfigured custom fields
'''
status_code = 400
code = 6
class SiteSuspendedException(StreamApiException):
'''
Raised when the site requesting the data is suspended
'''
status_code = 401
code = 7
def get_exceptions():
from stream import exceptions
classes = []
for k in dir(exceptions):
a = getattr(exceptions, k)
try:
if a and issubclass(a, StreamApiException):
classes.append(a)
except TypeError:
pass
return classes
def get_exception_dict():
classes = get_exceptions()
exception_dict = {c.code: c for c in classes}
return exception_dict