Skip to content

Commit

Permalink
Handle 428 for captcha submissions.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal authored and nicholas-signal committed Mar 27, 2024
1 parent e6eefac commit 5b10aa6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Expand Up @@ -124,6 +124,7 @@
import org.whispersystems.signalservice.internal.configuration.SignalServiceConfiguration;
import org.whispersystems.signalservice.internal.configuration.SignalUrl;
import org.whispersystems.signalservice.internal.crypto.AttachmentDigest;
import org.whispersystems.signalservice.internal.push.exceptions.CaptchaRejectedException;
import org.whispersystems.signalservice.internal.push.exceptions.DonationProcessorError;
import org.whispersystems.signalservice.internal.push.exceptions.DonationReceiptCredentialError;
import org.whispersystems.signalservice.internal.push.exceptions.ForbiddenException;
Expand Down Expand Up @@ -1247,7 +1248,12 @@ public void requestRateLimitPushChallenge() throws IOException {

public void submitRateLimitPushChallenge(String challenge) throws IOException {
String payload = JsonUtil.toJson(new SubmitPushChallengePayload(challenge));
makeServiceRequest(SUBMIT_RATE_LIMIT_CHALLENGE, "PUT", payload);
makeServiceRequest(SUBMIT_RATE_LIMIT_CHALLENGE, "PUT", payload, NO_HEADERS, (responseCode, body) -> {
if (responseCode == 428) {
throw new CaptchaRejectedException();
}
}, Optional.empty());

}

public void submitRateLimitRecaptchaChallenge(String challenge, String recaptchaToken) throws IOException {
Expand Down
@@ -0,0 +1,13 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/

package org.whispersystems.signalservice.internal.push.exceptions

import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException

/**
* Indicates that the captcha we submitted was not accepted by the server.
*/
class CaptchaRejectedException : NonSuccessfulResponseCodeException(428, "Captcha rejected by server.")

0 comments on commit 5b10aa6

Please sign in to comment.