def ParseJSONResponse(response):
  """Parse the JSON-encoded contents of the response body and return
  the python data object.
  """
  content_type = response.headers.get('Content-Type', '')
  if not any(content_type.startswith(x) for x in _CONTENT_TYPES):
    raise web.HTTPError(response.code, '%r' % response.headers)
  try:
    json_dict = json.loads(response.body)
    #logging.debug('parsed: %s' % repr(json_dict))
  except:
    if response.code == 200:
      raise
    json_dict = {'error': response.body}
  if response.code != 200:
    error = 'unknown'
    if isinstance(json_dict, dict) and json_dict.get('error'):
      error = json_dict.get('error')
    raise web.HTTPError(response.code, '%s' % error)
  return json_dict
dataset/ETHPy150Open viewfinderco/viewfinder/backend/www/www_util.py/ParseJSONResponse/original