-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathexceptions.py
More file actions
55 lines (43 loc) · 1.59 KB
/
Copy pathexceptions.py
File metadata and controls
55 lines (43 loc) · 1.59 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
from json import loads, JSONDecodeError
class PubNubException(Exception):
def __init__(self, errormsg="", status_code=0, pn_error=None, status=None):
self._errormsg = errormsg
self._status_code = status_code
self._pn_error = pn_error
self.status = status
if len(str(errormsg)) > 0 and int(status_code) > 0:
msg = str(pn_error) + " (" + str(status_code) + "): " + str(errormsg)
elif len(str(errormsg)) > 0:
msg = str(pn_error) + ": " + str(errormsg)
else:
msg = str(pn_error)
super(PubNubException, self).__init__(msg)
@property
def _status(self):
raise DeprecationWarning
return self.status
def get_status_code(self):
return self._status_code
def get_error_message(self):
result = ''
try:
error = loads(self._errormsg)
result = error.get('error')
except JSONDecodeError:
result = self._errormsg
if not result and self._pn_error:
result = self._pn_error
return result
class PubNubAsyncioException(Exception):
def __init__(self, result, status):
self.result = result
self.status = status
def __str__(self):
if self.status and hasattr(self.status, 'error_data') and self.status.error_data:
return str(self.status.error_data.exception)
return f"PubNubAsyncioException(result={self.result}, status={self.status})"
@staticmethod
def is_error():
return True
def value(self):
return self.status.error_data.exception