Skip to content

Handle proxy errors #6

Description

@Ragnaruk

If the response doesn't have a 2xx status code, the client raises ApiException.

if not 200 <= r.status <= 299:
    raise ApiException(http_resp=r)

Then, further up the exception is caught and handled.

except Exception as e:
    if not isinstance(e, ApiException) or is_auth_call(resource_path):
        raise e

    data = json.loads(e.body)

However, if the error was returned by a proxy (e.g. Cloudflare), then the type is not necessarily application/json.

In our case, Cloudflare sometimes returns html pages with status code 520, and json decoding raises exceptions.

I propose either checking the status code/content type before decoding the body or wrapping json.loads with try-except.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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