in cartography/intel/gcp/compute.py [0:0]
def _get_error_reason(http_error):
"""
Helper function to get an error reason out of the googleapiclient's HttpError object
This function copies the structure of
https://github.com/googleapis/google-api-python-client/blob/1d2e240a74d2bc0074dffbc57cf7d62b8146cb82/
googleapiclient/http.py#L111
At the moment this is the best way we know of to extract the HTTP failure reason.
Additionally, see https://github.com/googleapis/google-api-python-client/issues/662.
:param http_error: The googleapi HttpError object
:return: The error reason as a string
"""
try:
data = json.loads(http_error.content.decode('utf-8'))
if isinstance(data, dict):
reason = data['error']['errors'][0]['reason']
else:
reason = data[0]['error']['errors']['reason']
except (UnicodeDecodeError, ValueError, KeyError):
return ''
return reason