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.
If the response doesn't have a 2xx status code, the client raises ApiException.
Then, further up the exception is caught and handled.
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.