@@ -414,19 +414,30 @@ public <T> T fetch(@Nonnull Class<T> type) throws IOException {
414414 * if the server returns 4xx/5xx responses.
415415 */
416416 public <T > T [] fetchArray (@ Nonnull Class <T []> type ) throws IOException {
417- T [] result ;
418-
419- // for arrays we might have to loop for pagination
420- // use the iterator to handle it
421- List <T []> pages = new ArrayList <>();
422- int totalSize = 0 ;
423- for (Iterator <T []> iterator = asIterator (type , 0 ); iterator .hasNext ();) {
424- T [] nextResult = iterator .next ();
425- totalSize += Array .getLength (nextResult );
426- pages .add (nextResult );
417+ T [] result = null ;
418+
419+ try {
420+ // for arrays we might have to loop for pagination
421+ // use the iterator to handle it
422+ List <T []> pages = new ArrayList <>();
423+ int totalSize = 0 ;
424+ for (Iterator <T []> iterator = asIterator (type , 0 ); iterator .hasNext ();) {
425+ T [] nextResult = iterator .next ();
426+ totalSize += Array .getLength (nextResult );
427+ pages .add (nextResult );
428+ }
429+
430+ result = concatenatePages (type , pages , totalSize );
431+ } catch (GHException e ) {
432+ // if there was an exception inside the iterator it is wrapped as a GHException
433+ // if the wrapped exception is an IOException, throw that
434+ if (e .getCause () instanceof IOException ) {
435+ throw (IOException ) e .getCause ();
436+ } else {
437+ throw e ;
438+ }
427439 }
428440
429- result = concatenatePages (type , pages , totalSize );
430441 return result ;
431442 }
432443
0 commit comments