-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy patherror.py
More file actions
92 lines (61 loc) · 2.55 KB
/
Copy patherror.py
File metadata and controls
92 lines (61 loc) · 2.55 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
91
STATUS_CODES = {
'ValidationError': 400,
'ParameterError': 400,
'AuthError': 401,
'NotFoundError': 404,
'InternalError': 500
}
# Generic Exception
class BlockscoreError(Exception):
def __init__(self, message=None, json_body=None, http_status=None,
error_type=None, param=None, error_code=None):
super(BlockscoreError, self).__init__(message)
self.error_type = error_type
self.http_status = http_status
self.json_body = json_body
def __str__(self):
return "Status: {0}. Type: {1}, Message: {2}" \
.format(self.http_status, self.error_type, self.message)
# Input could not be validated.
class ValidationError(BlockscoreError):
def __init__(self, message=None, json_body=None, param=None,
error_type=None, error_code=None):
status_code = STATUS_CODES['ValidationError']
super(ValidationError, self).__init__(
message=message, error_type=error_type,
http_status=status_code, json_body=json_body, param=param)
self.error_code = error_code
self.param = param
def __str__(self):
return "Status: {0}. Type: {1}, Param: {2}, Code: {3}, Message: {4}" \
.format(self.http_status, self.error_type, self.param,
self.error_code, self.message)
# Required parameter missing
class ParameterError(BlockscoreError):
def __init__(self, message=None, json_body=None, error_type=None):
status_code = STATUS_CODES['ParameterError']
super(ParameterError, self).__init__(
message=message, error_type=error_type,
http_status=status_code, json_body=json_body)
# Invalid API Key
class AuthorizationError(BlockscoreError):
def __init__(self, message=None, json_body=None, error_type=None):
status_code = STATUS_CODES['AuthError']
super(AuthorizationError, self).__init__(
message=message, error_type=error_type,
http_status=status_code, json_body=json_body)
# Tried to reference a nonexistent endpoint
class NotFoundError(BlockscoreError):
def __init__(self, message=None, json_body=None, error_type=None):
status_code = STATUS_CODES['NotFoundError']
super(NotFoundError, self).__init__(
message=message, error_type=error_type,
http_status=status_code, json_body=json_body)
# Error on the Blockscore API
class InternalServerError(BlockscoreError):
def __init__(self, message=None, json_body=None, error_type=None):
status_code = STATUS_CODES['InternalError']
super(InternalServerError, self).__init__(
message=dict(), error_type=error_type,
http_status=status_code, json_body=json_body)
pass