forked from saleweaver/python-amazon-sp-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
91 lines (67 loc) · 2.53 KB
/
exceptions.py
File metadata and controls
91 lines (67 loc) · 2.53 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
82
83
84
85
86
87
88
89
90
91
class SellingApiException(Exception):
"""
Generic Exception
Parameters:
message: str The error message
amzn_code: str Amazon Error Code
error: list Amazon Error list
"""
code = 999
def __init__(self, error, headers):
try:
self.message = error[0].get('message')
self.amzn_code = error[0].get('code')
except IndexError:
pass
self.error = error
self.headers = headers
class SellingApiBadRequestException(SellingApiException):
"""
400 Request has missing or invalid parameters and cannot be parsed.
"""
code = 400
def __init__(self, error, headers=None):
super(SellingApiBadRequestException, self).__init__(error, headers)
class SellingApiForbiddenException(SellingApiException):
"""
403 Indicates access to the resource is forbidden. Possible reasons include Access Denied, Unauthorized, Expired Token, or Invalid Signature.
"""
code = 403
def __init__(self, error, headers=None):
super(SellingApiForbiddenException, self).__init__(error, headers)
class SellingApiNotFoundException(SellingApiException):
"""
404 The resource specified does not exist.
"""
code = 404
def __init__(self, error, headers=None):
super(SellingApiNotFoundException, self).__init__(error, headers)
class SellingApiRequestThrottledException(SellingApiException):
"""
429 The frequency of requests was greater than allowed.
"""
code = 429
def __init__(self, error, headers=None):
super(SellingApiRequestThrottledException, self).__init__(error, headers)
class SellingApiServerException(SellingApiException):
"""
500 An unexpected condition occurred that prevented the server from fulfilling the request.
"""
code = 500
def __init__(self, error, headers=None):
super(SellingApiServerException, self).__init__(error, headers)
class SellingApiTemporarilyUnavailableException(SellingApiException):
"""
503 Temporary overloading or maintenance of the server.
"""
code = 503
def __init__(self, error, headers=None):
super(SellingApiTemporarilyUnavailableException, self).__init__(error, headers)
def get_exception_for_code(code: int):
return {
400: SellingApiBadRequestException,
403: SellingApiForbiddenException,
429: SellingApiRequestThrottledException,
500: SellingApiServerException,
503: SellingApiTemporarilyUnavailableException
}.get(code, SellingApiException)