diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index 7e872d85925..30d1ba4671f 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -78,26 +78,28 @@ public function fetchAll(ApiInterface $api, $method, array $parameters = []) // set parameters per_page to GitHub max to minimize number of requests $api->setPerPage(100); - $result = $this->callApi($api, $method, $parameters); - $this->postFetch(); + try { + $result = $this->callApi($api, $method, $parameters); + $this->postFetch(); - if ($isSearch) { - $result = isset($result['items']) ? $result['items'] : $result; - } + if ($isSearch) { + $result = isset($result['items']) ? $result['items'] : $result; + } - while ($this->hasNext()) { - $next = $this->fetchNext(); + while ($this->hasNext()) { + $next = $this->fetchNext(); - if ($isSearch) { - $result = array_merge($result, $next['items']); - } else { - $result = array_merge($result, $next); + if ($isSearch) { + $result = array_merge($result, $next['items']); + } else { + $result = array_merge($result, $next); + } } + } finally { + // restore the perPage + $api->setPerPage($perPage); } - // restore the perPage - $api->setPerPage($perPage); - return $result; }