def _handle_ai_platform_response(uri, response):
  """Handle response to AI platform from both get/post calls.

  Args:
    uri: Request uri.
    response: Response from the request.
  Returns:
    Request results in json format.
  Raises:
    ValueError: When the request fails, the ValueError will be raised with
      either 404 error or the raw errors.
  """
  if response.status_code == 200:
    return response.json()
  elif response.status_code == 404:
    raise ValueError(('Target URI {} returns HTTP 404 error.\n'
                      'Please check if the project, model, and version names '
                      'are given correctly.'
                      ).format(uri))
  raise ValueError(('Target URI {} returns HTTP {} error.\n'
                    'Please check the raw error message: \n{}'
                    ).format(uri, response.status_code, response.text))