Issue #42 resolved

General error factory

Sebastian Rahlf
repo owner created an issue

The AWSError passes along a reference to the parsed XML document. When catching those errors it would be helpful if that reference was passed along as well.

Can you think of a general approach to solve this problem elegantly?

Comments (5)

  1. Sebastian Rahlf reporter
    • changed milestone to 0.3
    • removed version
    • marked as minor

    I'm thinking of something along the lines of

    def _make_error(exc, error_class, *args):
        """ 
        Creates an exception with all relevant information appended.
        """
        error = error_class(*(args or [exc.msg]))
        error.code = exc.code
        error.xml = exc.xml
        return error
    
    try:
        return self.parse(response.text)
    except AWSError as e:
    
        # simple errors
    
        errors = { 
            'InternalError': InternalError,
            'InvalidClientTokenId': InvalidClientTokenId,
            'MissingClientTokenId': MissingClientTokenId,
            'RequestThrottled': TooManyRequests,
            'Deprecated': DeprecatedOperation,
            'AWS.ECommerceService.NoExactMatches': NoExactMatchesFound
            'AccountLimitExceeded': AccountLimitExceeded,
        }
    
        if e.code in errors:
            raise _make_error(e, errors[e.code])
    
  2. Sebastian Rahlf reporter

    There is a new head in the default branch (support for Python 2) which will become version 0.2.8 at some point this week. With regards to you new exceptions, please see comments in commit.

  3. Log in to comment