Skip to content

Commit a4a31b0

Browse files
committed
Handle GitLabApiException nested in RuntimeException
1 parent 1b92244 commit a4a31b0

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,21 +251,31 @@ private List<Member> getMembersWithRetries() throws GitLabApiException, Interrup
251251
while (true) {
252252
try {
253253
return gitLabApi.getProjectApi().getAllMembers(projectPath);
254-
} catch (GitLabApiException e) {
255-
if (e.getHttpStatus() == 429) {
254+
} catch (GitLabApiException | RuntimeException e) {
255+
if (isRateLimitException(e)) {
256256
sleeper.sleep(delay);
257257
delay *= 2;
258258
attemptNb++;
259259
if (attemptNb > MAX_RETRIES) {
260260
throw e;
261261
}
262-
} else {
263-
throw e;
262+
continue;
264263
}
264+
throw e;
265265
}
266266
}
267267
}
268268

269+
private static boolean isRateLimitException(Exception e) {
270+
if (e instanceof GitLabApiException) {
271+
return ((GitLabApiException) e).getHttpStatus() == 429;
272+
} else if (e.getCause() != null && e.getCause().getClass().isAssignableFrom(GitLabApiException.class)) {
273+
GitLabApiException cause = (GitLabApiException) e.getCause();
274+
return cause.getHttpStatus() == 429;
275+
}
276+
return false;
277+
}
278+
269279
public Long getProjectId() {
270280
return projectId;
271281
}

0 commit comments

Comments
 (0)