evonove / mkm-sdk

33 stars 14 forks source link

Programmatic error handling #69

Closed JosephSBoyle closed 3 years ago

JosephSBoyle commented 3 years ago

I'm writing an app which needs direct access to the API error text. Currently mkmsdk raises a Exceptions.ConnectionError. Ideally I'd just access the response object directly even in the case of an error - I think this functionality could be useful for others who would like to store / manage error messages programmatically.

Would you accept a pull request that added the option to directly access api response when an error occurs messages?

silvanocerza commented 3 years ago

The Exceptions.ConnectionError contains the response, you can always access it if you need to. Something like this should work:

try:
    mkm.stock_management.get_stock()
except exceptions.ConnectionError as ex:
    print(ex.response.status_code)

Is this what you're trying to achieve or am I misunderstanding something?

JosephSBoyle commented 3 years ago

Hi, thanks for the response - what you're suggesting should work perfectly for me.

Best, Joe

silvanocerza commented 3 years ago

Glad to help, am closing this issue if the solution works for you. Feel free to repoen it if necessary.