Exclude RateLimitExceededException from fail-open checks

This commit is contained in:
Jon Chambers
2025-05-12 18:24:57 -04:00
committed by GitHub
parent cc7b030a41
commit 30c194c557
2 changed files with 84 additions and 1 deletions

View File

@@ -62,6 +62,10 @@ public class StaticRateLimiter implements RateLimiter {
throw new RateLimitExceededException(retryAfter);
}
} catch (final Exception e) {
if (e instanceof RateLimitExceededException rateLimitExceededException) {
throw rateLimitExceededException;
}
if (!config.failOpen()) {
throw e;
}
@@ -81,10 +85,15 @@ public class StaticRateLimiter implements RateLimiter {
return failedFuture(new RateLimitExceededException(retryAfter));
})
.exceptionally(throwable -> {
if (ExceptionUtils.unwrap(throwable) instanceof RateLimitExceededException rateLimitExceededException) {
throw ExceptionUtils.wrap(rateLimitExceededException);
}
if (config.failOpen()) {
return null;
}
throw ExceptionUtils.wrap(new RateLimitExceededException(null));
throw ExceptionUtils.wrap(throwable);
});
}