def _flatten_aggregated_list_results(project_id, paged_results, item_key,
sort_key='name'):
"""Flatten results and handle exceptions.
Args:
project_id (str): The project id the results are for.
paged_results (list): A list of paged API response objects.
[{page 1 results}, {page 2 results}, {page 3 results}, ...]
item_key (str): The name of the key within the inner "items" lists
containing the objects of interest.
sort_key (str): The name of the key to sort the results by before
returning.
Returns:
list: A sorted list of items.
Raises:
ApiNotEnabledError: Raised if the API is not enabled for the project.
ApiExecutionError: Raised if there is another error while calling the
API method.
"""
try:
return sorted(
api_helpers.flatten_aggregated_list_results(paged_results,
item_key),
key=lambda d: d.get(sort_key, ''))
except (errors.HttpError, HttpLib2Error) as e:
api_not_enabled, details = _api_not_enabled(e)
if api_not_enabled:
raise api_errors.ApiNotEnabledError(details, e)
raise api_errors.ApiExecutionError(project_id, e)
# pylint: enable=invalid-name
评论列表
文章目录