Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitgetLimited
GitHub Repository: BitgetLimited/V3-bitget-api-sdk
Path: blob/master/bitget-python-sdk-api/bitget/exceptions.py
732 views
1
# coding=utf-8
2
import json
3
4
class BitgetAPIException(Exception):
5
6
def __init__(self, response):
7
self.code = 0
8
try:
9
json_res = response.json()
10
except ValueError:
11
self.message = 'Invalid JSON error message from Bitget: {}'.format(response.text)
12
else:
13
if "code" in json_res.keys() and "msg" in json_res.keys():
14
self.code = json_res['code']
15
self.message = json_res['msg']
16
else:
17
self.code = 'Please wait a moment'
18
self.message = 'Maybe something is wrong'
19
20
self.status_code = response.status_code
21
self.response = response
22
self.request = getattr(response, 'request', None)
23
24
def __str__(self): # pragma: no cover
25
return 'API Request Error(code=%s): %s' % (self.code, self.message)
26
27
28
29
class BitgetRequestException(Exception):
30
31
def __init__(self, message):
32
self.message = message
33
34
def __str__(self):
35
return 'BitgetRequestException: %s' % self.message
36
37
38
39
class BitgetParamsException(Exception):
40
41
def __init__(self, message):
42
self.message = message
43
44
def __str__(self):
45
return 'BitgetParamsException: %s' % self.message
46
47