1. michilu
  2. python-amazon-product-api

Commits

Sebastian Rahlf  committed 5eeee8e

All errors are subclasses of AWSError now.

  • Participants
  • Parent commits 642a459
  • Branches default

Comments (0)

Files changed (4)

File amazonproduct/errors.py

View file
     'UnknownLocale'
 ]
 
-class UnknownLocale (Exception):
+class AWSError (Exception):
+    """
+    Generic AWS error message.
+    """
+    def __init__(self, *args, **kwargs):
+        self.code = kwargs.pop('code', None)
+        self.msg = kwargs.pop('msg', None)
+        self.xml = kwargs.pop('xml', None)
+        Exception.__init__(self)
+    def __str__(self): # pragma: no cover
+        if self.code is not None:
+            return '%(code)s: %(msg)s' % self.__dict__
+        return Exception.__str__(self)
+
+class UnknownLocale (AWSError):
     """
     Raised when unknown locale is specified.
     """
 
-class AWSError (Exception):
-    """
-    Generic AWS error message.
-    """
-    def __init__(self, code, msg):
-        Exception.__init__(self)
-        self.code = code
-        self.msg = msg
-    def __str__(self): # pragma: no cover
-        return '%(code)s: %(msg)s' % self.__dict__
-
-class InternalError (Exception):
+class InternalError (AWSError):
     """
     Amazon encountered an internal error. Please try again.
     """
 
-class InvalidClientTokenId (Exception):
+class InvalidClientTokenId (AWSError):
     """
     The AWS Access Key Id you provided does not exist in Amazon's records.
     """
 
-class MissingClientTokenId (Exception):
+class MissingClientTokenId (AWSError):
     """
     Request must contain AWSAccessKeyId or X.509 certificate.
     """
 
-class MissingParameters (Exception):
+class MissingParameters (AWSError):
     """
     Your request is missing required parameters. Required parameters include
     XXX.
     """
 
-class InvalidSearchIndex (Exception):
+class InvalidSearchIndex (AWSError):
     """
     The value specified for SearchIndex is invalid. Valid values include:
 
     Watches
     """
 
-class InvalidResponseGroup (Exception):
+class InvalidResponseGroup (AWSError):
     """
     The specified ResponseGroup parameter is invalid. Valid response groups for
     ItemLookup requests include:
     Variations.
     """
 
-class InvalidParameterValue (Exception):
+class InvalidParameterValue (AWSError):
     """
     The specified ItemId parameter is invalid. Please change this value and
     retry your request.
     """
 
-class InvalidListType (Exception):
+class InvalidListType (AWSError):
     """
     The value you specified for ListType is invalid. Valid values include:
     BabyRegistry, Listmania, WeddingRegistry, WishList.
     """
 
-class NoSimilarityForASIN (Exception):
+class NoSimilarityForASIN (AWSError):
     """
     When you specify multiple items, it is possible for there to be no
     intersection of similar items.
     """
 
-class NoExactMatchesFound (Exception):
+class NoExactMatchesFound (AWSError):
     """
     We did not find any matches for your request.
     """
 
-class TooManyRequests (Exception):
+class TooManyRequests (AWSError):
     """
     You are submitting requests too quickly and your requests are being
     throttled. If this is the case, you need to slow your request rate to one
     request per second.
     """
 
-class NotEnoughParameters (Exception):
+class NotEnoughParameters (AWSError):
     """
     Your request should have at least one parameter which you did not submit.
     """
 
-class InvalidParameterCombination (Exception):
+class InvalidParameterCombination (AWSError):
     """
     Your request contained a restricted parameter combination.
     """
 
-class DeprecatedOperation (Exception):
+class DeprecatedOperation (AWSError):
     """
     The specified feature (operation) is deprecated.
     """
 
-class InvalidOperation (Exception):
+class InvalidOperation (AWSError):
     """
     The specified feature (operation) is invalid.
     """
 
-class InvalidCartItem (Exception):
+class InvalidCartItem (AWSError):
     """
     The item you specified, ???, is not eligible to be added to the cart. Check
     the item's availability to make sure it is available.
     """
 
-class ItemAlreadyInCart (Exception):
+class ItemAlreadyInCart (AWSError):
     """
     The item you specified, ???, is already in your cart.
     
     .. deprecated:: 0.2.6
     """
 
-class CartInfoMismatch (Exception):
+class CartInfoMismatch (AWSError):
     """
     Your request contains an invalid AssociateTag, CartId and HMAC combination.
     Please verify the AssociateTag, CartId, HMAC and retry.
     returned to you during the CartCreate operation.
     """
 
-class InvalidCartId (Exception):
+class InvalidCartId (AWSError):
     """
     Your request contains an invalid value for CartId. Please check your CartId
     and retry your request.

File amazonproduct/processors/etree.py

View file
         ns = extract_nspace(root)
         errors = root.findall('.//%sError' % ns)
         for error in errors:
-            code = error.findtext('./%sCode' % ns)
-            msg = error.findtext('./%sMessage' % ns)
-            raise AWSError(code, msg)
+            raise AWSError(code=error.findtext('./%sCode' % ns),
+                msg=error.findtext('./%sMessage' % ns), xml=root)
         return root
 
     def __repr__(self):

File amazonproduct/processors/minidom.py

View file
     def parse(self, fp):
         root = xml.dom.minidom.parse(fp)
         # parse errors
-        for error in root.getElementsByTagName('Error'):
-            code = error.getElementsByTagName('Code')[0].firstChild.nodeValue
-            msg = error.getElementsByTagName('Message')[0].firstChild.nodeValue
-            raise AWSError(code, msg)
+        for er in root.getElementsByTagName('Error'):
+            raise AWSError(
+                code=er.getElementsByTagName('Code')[0].firstChild.nodeValue,
+                msg=er.getElementsByTagName('Message')[0].firstChild.nodeValue,
+                xml=root)
         return root
 

File amazonproduct/processors/objectify.py

View file
             errors = root.xpath('//Error')
 
         for error in errors:
-            code = error.Code.text
-            msg = error.Message.text
-            raise AWSError(code, msg)
+            raise AWSError(code=error.Code.text,
+                msg=error.Message.text, xml=root)
 
         return root