Package coprs :: Package rest_api :: Module exceptions
[hide private]
[frames] | no frames]

Source Code for Module coprs.rest_api.exceptions

 1  # coding: utf-8 
 2  import six 
 3   
 4   
5 -class ApiError(Exception):
6 - def __init__(self, code, msg, data=None, **kwargs):
7 super(ApiError, self).__init__(**kwargs) 8 9 self.code = code 10 self.data = data 11 self.msg = msg 12 13 self.headers = kwargs.get("headers", {})
14
15 - def __str__(self):
16 return str(self.data)
17 18 if six.PY2:
19 - def __unicode__(self):
20 return unicode(self.data)
21 22
23 -class AuthFailed(ApiError):
24 - def __init__(self, msg=None, data=None, **kwargs):
25 if msg is None: 26 msg = "Authorization failed" 27 super(AuthFailed, self).__init__(401, msg=msg, data=data, **kwargs) 28 self.headers["Authorization"] = "Basic"
29 30
31 -class AccessForbidden(ApiError):
32 - def __init__(self, msg=None, data=None, **kwargs):
33 if msg is None: 34 msg = "Access forbidden" 35 super(AccessForbidden, self).__init__(403, msg=msg, data=data, **kwargs)
36 37
38 -class ObjectNotFoundError(ApiError):
39 - def __init__(self, msg=None, data=None, **kwargs):
40 if msg is None: 41 msg = "Requested object wasn't found" 42 super(ObjectNotFoundError, self).__init__(404, msg=msg, data=data, **kwargs)
43 44
45 -class ObjectAlreadyExists(ApiError):
46 - def __init__(self, msg=None, data=None, **kwargs):
47 if msg is None: 48 msg = "Operational error, trying to create existing object" 49 50 super(ObjectAlreadyExists, self).__init__(409, msg=msg, data=data, **kwargs)
51 52
53 -class MalformedRequest(ApiError):
54 - def __init__(self, msg=None, data=None, **kwargs):
55 if msg is None: 56 msg = "Given request contains errors or couldn't be executed in the current context" 57 58 super(MalformedRequest, self).__init__(400, msg=msg, data=data, **kwargs)
59 60
61 -class CannotProcessRequest(ApiError):
62 - def __init__(self, msg=None, data=None, **kwargs):
63 if msg is None: 64 msg = "Cannot process given request" 65 66 super(CannotProcessRequest, self).__init__(400, msg=msg, data=data, **kwargs)
67 68
69 -class ServerError(ApiError):
70 - def __init__(self, msg=None, data=None, **kwargs):
71 if msg is None: 72 msg = "Unhandled server error, please contact site administrator" 73 super(ServerError, self).__init__(500, msg=msg, data=data, **kwargs)
74