Skip to content

Commit 82e52ef

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

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,36 @@ 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+
boolean isRateLimitException = false;
271+
if (e instanceof GitLabApiException) {
272+
if (((GitLabApiException) e).getHttpStatus() == 429) {
273+
isRateLimitException = true;
274+
}
275+
} else {
276+
if (e.getCause().getClass().isAssignableFrom(GitLabApiException.class)) {
277+
GitLabApiException cause = (GitLabApiException) e.getCause();
278+
if (cause.getHttpStatus() == 429) {
279+
isRateLimitException = true;
264280
}
265281
}
266282
}
283+
return isRateLimitException;
267284
}
268285

269286
public Long getProjectId() {

0 commit comments

Comments
 (0)