python-sparkpost icon indicating copy to clipboard operation
python-sparkpost copied to clipboard

External lib errors wrapping

Open velykanov opened this issue 5 years ago • 0 comments

Hi there!

I've noticed that in this project requests library is used to make queries. However there is no handling of potential exceptions in external library.

I want you to add some external exceptions wrapping into SparkPostException at least (since I've no access to push into the repo).

The change is pretty simple and would make your code much better, because it's insane when external lib raises errors from another external lib that is used in this one.

My suggestion is something like this (compatible with both Python2.x and Python 3.x):

try:
    response = self.sess.request(method, uri, headers=headers, **kwargs)
except requests.exceptions.RequestException as exc:
    raise SparkPostException(exc)

In case of dropping Python 2.x support from exc part could be added for providing more details about external lib exception.

Thanks a lot and have a nice day!

velykanov avatar Sep 23 '19 13:09 velykanov