Webhose / webzio-python

Webz.io Python SDK
https://webz.io
MIT License
42 stars 12 forks source link

All API errors come through as `Exception` #2

Open jimr opened 7 years ago

jimr commented 7 years ago

It would be good to either check for specific status codes / messages from the upstream API[1] or even just use the raise_for_status[2] method from requests. At the moment I have to inspect exception.message in order to figure out what the actual issue was when connecting to the API. I think it would be preferable to write, e.g.:

try:
    result = run_query()
except RateLimitException:
    time.sleep(5)
    result = run_query()

versus what I have now:

try:
    result = run_query()
except Exception as ex:
    if ex.message = 'rate limit exceeded':
        time.sleep(5)
        result = run_query()
    else:
        raise

It might also be useful if the "quota exceeded" error response returned 402 rather than 429, but that's a general issue, not specific to the Python library. Thanks!

[1] https://docs.webhose.io/docs/things-every-developer-should-know#section-http-status-codes [2] http://docs.python-requests.org/en/master/user/quickstart/#response-status-codes