-
Notifications
You must be signed in to change notification settings - Fork 12
/
exceptions.py
46 lines (31 loc) · 1.23 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
# coding=utf-8
class OkexAPIException(Exception):
def __init__(self, response):
print(response.text + ', ' + str(response.status_code))
self.code = 0
try:
json_res = response.json()
except ValueError:
self.message = 'Invalid JSON error message from Okex: {}'.format(response.text)
else:
if "code" in json_res.keys() and "message" in json_res.keys():
self.code = json_res['code']
self.message = json_res['message']
else:
self.code = 'None'
self.message = 'Server error'
self.status_code = response.status_code
self.response = response
self.request = getattr(response, 'request', None)
def __str__(self): # pragma: no cover
return 'API Request Error(code=%s): %s' % (self.code, self.message)
class OkexRequestException(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return 'OkexRequestException: %s' % self.message
class OkexParamsException(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return 'OkexParamsException: %s' % self.message