moltin / python-sdk

Moltin python SDK
MIT License
6 stars 9 forks source link

Improve handling of API error responses #2

Open jordanmkoncz opened 8 years ago

jordanmkoncz commented 8 years ago

I've been getting an error response from the API (see https://github.com/moltin/issues/issues/22 for more info). The way that Moltin's Python SDK currently handles error responses from the API meant that the only thing that was being displayed in the console was the following:

RequestError: billing_address

This is obviously not very informative and I spent a while passing different variations of data to Moltin hoping to get a successful response back. After no success I dropped into debug mode and set a breakpoint so that I could view the raw response from the API, which turned out to be the following:

{
    'status': False,
    'errors': {
        'billing_address': ["Address 'postcode' not found"]
    }
}

I think the error handling in the with_error_handling() function should be improved so that when there is an error response from the API, the output to console includes all the error information provided by the API.

jordanmkoncz commented 8 years ago

I've submitted a pull request that fixes this issue. Currently, an example of the exception message for an API response with multiple errors would be:

RequestError: billing_address, gateway

With the changes in the submitted pull request, the exception message for the same API response would be:

RequestError: 
billing_address: Address 'postcode' not found
gateway: 'dummy' is not a valid gateway