forked from ma2za/python-substack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
32 lines (24 loc) · 911 Bytes
/
exceptions.py
File metadata and controls
32 lines (24 loc) · 911 Bytes
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
import json
class SubstackAPIException(Exception):
def __init__(self, status_code, text):
try:
json_res = json.loads(text)
except ValueError:
self.message = f"Invalid JSON error message from Substack: {text}"
else:
self.message = ", ".join(
list(
map(lambda error: error.get("msg", ""), json_res.get("errors", []))
)
)
self.message = self.message or json_res.get("error", "")
self.status_code = status_code
def __str__(self):
return f"APIError(code={self.status_code}): {self.message}"
class SubstackRequestException(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return f"SubstackRequestException: {self.message}"
class SectionNotExistsException(SubstackRequestException):
pass