-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexceptions.py
More file actions
81 lines (52 loc) · 2.09 KB
/
exceptions.py
File metadata and controls
81 lines (52 loc) · 2.09 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import six
class SyncanoException(Exception):
"""
General Syncano client exception
"""
def __init__(self, reason=None, *args):
super(SyncanoException, self).__init__(reason, *args)
self.reason = reason
def __repr__(self):
return self.reason
def __str__(self):
return self.reason
class SyncanoValueError(SyncanoException):
"""A Python :class:`ValueError` error occurred."""
class SyncanoRequestError(SyncanoException):
"""An HTTP error occurred.
:ivar status_code: HTTP status code e.g: 404
:ivar reason: Error text representation
"""
def __init__(self, status_code, reason, *args):
self.status_code = status_code
if isinstance(reason, dict):
joined_details = (''.join(reason.get(k, '')) for k in ['detail', 'error', '__all__'])
message = ''.join(joined_details)
if not message:
for name, value in six.iteritems(reason):
if isinstance(value, (list, dict)):
value = ', '.join(value)
message += '{0}: {1}\n'.format(name, value)
reason = message
super(SyncanoRequestError, self).__init__(reason, *args)
def __repr__(self):
return '{0} {1}'.format(self.status_code, self.reason)
def __str__(self):
return '{0} {1}'.format(self.status_code, self.reason)
class SyncanoValidationError(SyncanoValueError):
"""A validation error occurred."""
class SyncanoFieldError(SyncanoValidationError):
"""A field error occurred.
:ivar field_name: Related field name
"""
field_name = None
def __repr__(self):
return '{0}: {1}'.format(self.field_name, self.reason)
def __str__(self):
return '{0}: {1}'.format(self.field_name, self.reason)
class SyncanoDoesNotExist(SyncanoException):
"""Syncano object doesn't exist error occurred."""
class RevisionMismatchException(SyncanoRequestError):
"""Revision do not match with expected one"""
class UserNotFound(SyncanoRequestError):
"""Special error to handle user not found case."""