import json


def GetHttpErrorMessage(error):
  """Returns a human readable string representation from the http response.

  Args:
    error: apitools HttpException representing the error response.

  Returns:
    A human readable string representation of the error.
  """
  code = getattr(error.response, 'status', '')  # Example: 403
  status = ''
  message = ''
  try:
    data = json.loads(error.content)
    if 'error' in data:
      error_info = data['error']
      code = error_info.get('code', code)  # Example: 403
      status = error_info.get('status', '')  # Example: PERMISSION_DENIED
      message = error_info.get('message', '')
  except (ValueError, TypeError):
    message = error.content
  if not status and not message:
    # Example: 'HTTPError 403'
    return 'HTTPError {0}'.format(code)
  if not status or not message:
    # Example: 'PERMISSION_DENIED' or 'You do not have permission to access X'
    return '{0}'.format(status or message)
  # Example: 'PERMISSION_DENIED: You do not have permission to access X'
  return '{0}: {1}'.format(status, message)