-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexceptions.py
27 lines (21 loc) · 865 Bytes
/
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
class FinnhubAPIException(Exception):
def __init__(self, response):
self.code = 0
try:
json_response = response.json()
except ValueError:
self.message = "JSON error message from Finnhub: {}".format(response.text)
else:
if "error" not in json_response:
self.message = "Wrong json format from FinnhubAPI"
else:
self.message = json_response["error"]
self.status_code = response.status_code
self.response = response
def __str__(self):
return "FinnhubAPIException(status_code: {}): {}".format(self.status_code, self.message)
class FinnhubRequestException(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return "FinnhubRequestException: {}".format(self.message)