Migrate to 429 for all ratelimit responses

This commit is contained in:
Katherine
2024-08-05 12:02:11 -07:00
committed by GitHub
parent 10d559bbb5
commit 0e4625ef88
33 changed files with 63 additions and 110 deletions

View File

@@ -134,7 +134,7 @@ public class AccountControllerV2 {
// Only verify and check reglock if there's a data change to be made...
if (!authenticatedAccount.getAccount().getNumber().equals(number)) {
RateLimiter.adaptLegacyException(() -> rateLimiters.getRegistrationLimiter().validate(number));
rateLimiters.getRegistrationLimiter().validate(number);
final PhoneVerificationRequest.VerificationType verificationType = phoneVerificationTokenManager.verify(number,
request);

View File

@@ -28,28 +28,21 @@ public class RateLimitExceededException extends Exception implements Convertible
@Nullable
private final Duration retryDuration;
private final boolean legacy;
/**
* Constructs a new exception indicating when it may become safe to retry
*
* @param retryDuration A duration to wait before retrying, null if no duration can be indicated
* @param legacy whether to use a legacy status code when mapping the exception to an HTTP response
*/
public RateLimitExceededException(@Nullable final Duration retryDuration, final boolean legacy) {
public RateLimitExceededException(@Nullable final Duration retryDuration) {
super(null, null, true, false);
this.retryDuration = retryDuration;
this.legacy = legacy;
}
public Optional<Duration> getRetryDuration() {
return Optional.ofNullable(retryDuration);
}
public boolean isLegacy() {
return legacy;
}
@Override
public Status grpcStatus() {
return Status.RESOURCE_EXHAUSTED;

View File

@@ -111,7 +111,7 @@ public class RegistrationController {
throw new WebApplicationException("Invalid signature", 422);
}
RateLimiter.adaptLegacyException(() -> rateLimiters.getRegistrationLimiter().validate(number));
rateLimiters.getRegistrationLimiter().validate(number);
final PhoneVerificationRequest.VerificationType verificationType = phoneVerificationTokenManager.verify(number,
registrationRequest);

View File

@@ -173,9 +173,7 @@ public class VerificationController {
} catch (final CompletionException e) {
if (ExceptionUtils.unwrap(e) instanceof RateLimitExceededException re) {
RateLimiter.adaptLegacyException(() -> {
throw re;
});
throw re;
}
throw new ServerErrorException(Response.Status.INTERNAL_SERVER_ERROR, e);
@@ -318,9 +316,8 @@ public class VerificationController {
final boolean pushChallengePresent = updateVerificationSessionRequest.pushChallenge() != null;
if (pushChallengePresent) {
RateLimiter.adaptLegacyException(
() -> rateLimiters.getVerificationPushChallengeLimiter()
.validate(registrationServiceSession.encodedSessionId()));
rateLimiters.getVerificationPushChallengeLimiter()
.validate(registrationServiceSession.encodedSessionId());
}
final boolean pushChallengeMatches;
@@ -383,8 +380,7 @@ public class VerificationController {
return verificationSession;
}
RateLimiter.adaptLegacyException(
() -> rateLimiters.getVerificationCaptchaLimiter().validate(registrationServiceSession.encodedSessionId()));
rateLimiters.getVerificationCaptchaLimiter().validate(registrationServiceSession.encodedSessionId());
final AssessmentResult assessmentResult;
try {
@@ -507,7 +503,7 @@ public class VerificationController {
throw new ClientErrorException(response);
}
throw new RateLimitExceededException(rateLimitExceededException.getRetryDuration().orElse(null), false);
throw new RateLimitExceededException(rateLimitExceededException.getRetryDuration().orElse(null));
} else if (unwrappedException instanceof RegistrationServiceException registrationServiceException) {
throw registrationServiceException.getRegistrationSession()
@@ -584,7 +580,7 @@ public class VerificationController {
throw new ClientErrorException(response);
}
throw new RateLimitExceededException(rateLimitExceededException.getRetryDuration().orElse(null), false);
throw new RateLimitExceededException(rateLimitExceededException.getRetryDuration().orElse(null));
} else if (unwrappedException instanceof RegistrationServiceException registrationServiceException) {

View File

@@ -24,7 +24,7 @@ public class VerificationSessionRateLimitExceededException extends RateLimitExce
public VerificationSessionRateLimitExceededException(
final RegistrationServiceSession registrationServiceSession, @Nullable final Duration retryDuration,
final boolean legacy) {
super(retryDuration, legacy);
super(retryDuration);
this.registrationServiceSession = registrationServiceSession;
}