def make_exception(response, content, error_info=None, use_json=True):
 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:
    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 KeyError:
  error = GoogleCloudError(message, errors)
  error.code = response.status
 else:
  error = klass(message, errors)
 return error

def make_exception ( response , content , error_info = None , use_json = True ) : 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 : 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 KeyError : error = GoogleCloudError ( message , errors ) error . code = response . status else : error = klass ( message , errors ) return error
factory: create exception based on http response code .