-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexceptions.py
More file actions
51 lines (40 loc) · 1.25 KB
/
exceptions.py
File metadata and controls
51 lines (40 loc) · 1.25 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
import json
class PayloadError(Exception):
http_code = None
details = None
response = None
def __init__( self, description=None, response=None ):
if not description:
description = self.__class__.__name__
if response:
self.response = response
self.details = self.response.get('details')
description += '\n\n'+json.dumps(
response,
sort_keys=True,
indent=4
)
super(PayloadError, self).__init__( description )
class UnknownResponse(PayloadError):
pass
class BadRequest(PayloadError):
http_code = 400
class TransactionDeclined(BadRequest):
def __init__(self, *args, **kwargs):
from .utils import map_object
super().__init__(*args, **kwargs)
self.transaction = self.details = map_object(self.response['details'])
class InvalidAttributes(BadRequest):
pass
class Unauthorized(PayloadError):
http_code = 401
class Forbidden(PayloadError):
http_code = 403
class NotFound(PayloadError):
http_code = 404
class TooManyRequests(PayloadError):
http_code = 429
class InternalServerError(PayloadError):
http_code = 500
class ServiceUnavailable(PayloadError):
http_code = 503