|
| 1 | +class SellingApiException(BaseException): |
| 2 | + """ |
| 3 | + Generic Exception |
| 4 | +
|
| 5 | + Parameters: |
| 6 | +
|
| 7 | + message: str The error message |
| 8 | + amzn_code: str Amazon Error Code |
| 9 | + error: list Amazon Error list |
| 10 | +
|
| 11 | + """ |
| 12 | + |
| 13 | + def __init__(self, error): |
| 14 | + try: |
| 15 | + self.message = error[0].get('message') |
| 16 | + self.amzn_code = error[0].get('code') |
| 17 | + except IndexError: |
| 18 | + pass |
| 19 | + self.error = error |
| 20 | + |
| 21 | + |
| 22 | +class SellingApiBadRequestException(SellingApiException): |
| 23 | + """ |
| 24 | + 400 Request has missing or invalid parameters and cannot be parsed. |
| 25 | + """ |
| 26 | + code = 400 |
| 27 | + |
| 28 | + def __init__(self, error): |
| 29 | + super(SellingApiBadRequestException, self).__init__(error) |
| 30 | + |
| 31 | + |
| 32 | +class SellingApiForbiddenException(SellingApiException): |
| 33 | + """ |
| 34 | + 403 Indicates access to the resource is forbidden. Possible reasons include Access Denied, Unauthorized, Expired Token, or Invalid Signature. |
| 35 | + """ |
| 36 | + code = 403 |
| 37 | + |
| 38 | + def __init__(self, error): |
| 39 | + super(SellingApiForbiddenException, self).__init__(error) |
| 40 | + |
| 41 | + |
| 42 | +class SellingApiNotFoundException(SellingApiException): |
| 43 | + """ |
| 44 | + 404 The resource specified does not exist. |
| 45 | + """ |
| 46 | + code = 404 |
| 47 | + |
| 48 | + def __init__(self, error): |
| 49 | + super(SellingApiNotFoundException, self).__init__(error) |
| 50 | + |
| 51 | + |
| 52 | +class SellingApiRequestThrottledException(SellingApiException): |
| 53 | + """ |
| 54 | + 429 The frequency of requests was greater than allowed. |
| 55 | + """ |
| 56 | + code = 429 |
| 57 | + |
| 58 | + def __init__(self, error): |
| 59 | + super(SellingApiRequestThrottledException, self).__init__(error) |
| 60 | + |
| 61 | + |
| 62 | +class SellingApiServerException(SellingApiException): |
| 63 | + """ |
| 64 | + 500 An unexpected condition occurred that prevented the server from fulfilling the request. |
| 65 | + """ |
| 66 | + code = 500 |
| 67 | + |
| 68 | + def __init__(self, error): |
| 69 | + super(SellingApiServerException, self).__init__(error) |
| 70 | + |
| 71 | + |
| 72 | +class SellingApiTemporarilyUnavailableException(SellingApiException): |
| 73 | + """ |
| 74 | + 503 Temporary overloading or maintenance of the server. |
| 75 | + """ |
| 76 | + code = 503 |
| 77 | + |
| 78 | + def __init__(self, error): |
| 79 | + super(SellingApiTemporarilyUnavailableException, self).__init__(error) |
| 80 | + |
| 81 | + |
| 82 | +def get_exception_for_code(code: int): |
| 83 | + return { |
| 84 | + 400: SellingApiBadRequestException, |
| 85 | + 403: SellingApiForbiddenException, |
| 86 | + 429: SellingApiRequestThrottledException, |
| 87 | + 500: SellingApiServerException, |
| 88 | + 503: SellingApiTemporarilyUnavailableException |
| 89 | + }.get(code, SellingApiException) |
0 commit comments