def make_exception(response, content, error_info=None, use_json=True):
    """Factory:  create exception based on HTTP response code.

    :type response: :class:`httplib2.Response` or other HTTP response object
    :param response: A response object that defines a status code as the
                     status attribute.

    :type content: string or dictionary
    :param content: The body of the HTTP error response.

    :type error_info: string
    :param error_info: Optional string giving extra information about the
                       failed request.

    :type use_json: bool
    :param use_json: Flag indicating if ``content`` is expected to be JSON.

    :rtype: instance of :class:`GCloudError`, or a concrete subclass.
    :returns: Exception specific to the error response.
    """
    if isinstance(content, six.binary_type):
        content = content.decode('utf-8')

    if isinstance(content, six.string_types):
        payload = None
        if use_json:
            try:
                payload = json.loads(content)
            except ValueError:
                # Expected JSON but received something else.
                pass
        if payload is None:
            payload = {'error': {'message': content}}
    else:
        payload = content

    message = payload.get('error', {}).get('message', '')
    errors = payload.get('error', {}).get('errors', ())

    if error_info is not None:
        message += ' (%s)' % (error_info,)

    try:
        klass = _HTTP_CODE_TO_EXCEPTION[response.status]
    except __HOLE__:
        error = GCloudError(message, errors)
        error.code = response.status
    else:
        error = klass(message, errors)
    return error
dataset/ETHPy150Open GoogleCloudPlatform/gcloud-python/gcloud/exceptions.py/make_exception