Skip to content

All API errors come through as Exception #2

@jimr

Description

@jimr

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions