Skip to content

Commit

Permalink
Merge pull request #749 from madurangasiriwardena/stackoverflow
Browse files Browse the repository at this point in the history
Fix stack overflow error
  • Loading branch information
madurangasiriwardena authored Dec 4, 2024
2 parents eb2c7e7 + 51438ce commit e4ca189
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,17 @@ public static Map<String, String> buildPaginationLinks(int limit, int currentOff

private static int calculateOffsetForPreviousLink(int offset, int limit, int total) {

if (limit <= 0) {
// If limit is 0 or negative, consider it as 0 and build the previous page.
return offset;
}

int newOffset = (offset - limit);
if (newOffset < total) {
return newOffset;
}

// If offset is greater than total, go back by the chunks of limit until a proper page is found.
return calculateOffsetForPreviousLink(newOffset, limit, total);
}

Expand Down

0 comments on commit e4ca189

Please sign in to comment.