def check_error(res, error_enum):
  """Raise if the result has an error, otherwise return the result."""
  if res.HasField("error"):
    enum_name = error_enum.DESCRIPTOR.full_name
    error_name = error_enum.Name(res.error)
    details = getattr(res, "error_details", "<none>")
    raise RequestError("%s.%s: '%s'" % (enum_name, error_name, details), res)
  return res