From 29bcf65ece840e3e49a34c2b87f68d71a9149cc2 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Thu, 15 Sep 2016 09:09:15 -0700 Subject: [PATCH] Let's not break everyone with paged list yet --- .../java/com/microsoft/azure/PagedList.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java b/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java index 86a4f9afcd6a3..46c02402ed531 100644 --- a/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java +++ b/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java @@ -7,6 +7,9 @@ package com.microsoft.azure; +import com.microsoft.rest.RestException; + +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -51,13 +54,17 @@ public PagedList(Page page) { } private void cachePage(String nextPageLink) { - while (nextPageLink != null) { - cachedPage = nextPage(nextPageLink); - nextPageLink = cachedPage.getNextPageLink(); - if (hasNextPage()) { - // a legit, non-empty page has been fetched, otherwise keep fetching - break; + try { + while (nextPageLink != null) { + cachedPage = nextPage(nextPageLink); + nextPageLink = cachedPage.getNextPageLink(); + if (hasNextPage()) { + // a legit, non-empty page has been fetched, otherwise keep fetching + break; + } } + } catch (IOException ex) { + throw new RuntimeException(ex); } } @@ -66,8 +73,10 @@ private void cachePage(String nextPageLink) { * * @param nextPageLink the link to get the next page of items. * @return the {@link Page} object storing a page of items and a link to the next page. + * @throws RestException thrown if an error is raised from Azure. + * @throws IOException thrown if there's any failure in deserialization. */ - public abstract Page nextPage(String nextPageLink); + public abstract Page nextPage(String nextPageLink) throws RestException, IOException; /** * If there are more pages available.