Skip to content

Commit 472b8f7

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

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,35 @@ 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;
263+
}
264+
throw e;
265+
}
266+
}
267+
}
268+
269+
private static boolean isRateLimitException(Exception e) {
270+
if (e instanceof GitLabApiException) {
271+
if (((GitLabApiException) e).getHttpStatus() == 429) {
272+
return true;
273+
}
274+
} else {
275+
if (e.getCause().getClass().isAssignableFrom(GitLabApiException.class)) {
276+
GitLabApiException cause = (GitLabApiException) e.getCause();
277+
if (cause.getHttpStatus() == 429) {
278+
return true;
264279
}
265280
}
266281
}
282+
return false;
267283
}
268284

269285
public Long getProjectId() {

0 commit comments

Comments
 (0)