Improve error message if captcha is rejected by server

Fixes #1328
This commit is contained in:
AsamK 2024-02-26 22:13:57 +01:00
parent e77d9e3d60
commit 189b21dbde
5 changed files with 40 additions and 4 deletions

View file

@ -2,6 +2,7 @@ package org.asamk.signal.manager;
import org.asamk.signal.manager.api.AlreadyReceivingException;
import org.asamk.signal.manager.api.AttachmentInvalidException;
import org.asamk.signal.manager.api.CaptchaRejectedException;
import org.asamk.signal.manager.api.CaptchaRequiredException;
import org.asamk.signal.manager.api.Configuration;
import org.asamk.signal.manager.api.Device;
@ -136,7 +137,10 @@ public interface Manager extends Closeable {
void deleteAccount() throws IOException;
void submitRateLimitRecaptchaChallenge(String challenge, String captcha) throws IOException;
void submitRateLimitRecaptchaChallenge(
String challenge,
String captcha
) throws IOException, CaptchaRejectedException;
List<Device> getLinkedDevices() throws IOException;

View file

@ -0,0 +1,16 @@
package org.asamk.signal.manager.api;
public class CaptchaRejectedException extends Exception {
public CaptchaRejectedException() {
super("Captcha rejected");
}
public CaptchaRejectedException(final String message) {
super(message);
}
public CaptchaRejectedException(final String message, final Throwable cause) {
super(message, cause);
}
}

View file

@ -19,6 +19,7 @@ package org.asamk.signal.manager.internal;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.AlreadyReceivingException;
import org.asamk.signal.manager.api.AttachmentInvalidException;
import org.asamk.signal.manager.api.CaptchaRejectedException;
import org.asamk.signal.manager.api.CaptchaRequiredException;
import org.asamk.signal.manager.api.Configuration;
import org.asamk.signal.manager.api.Device;
@ -407,10 +408,17 @@ public class ManagerImpl implements Manager {
}
@Override
public void submitRateLimitRecaptchaChallenge(String challenge, String captcha) throws IOException {
public void submitRateLimitRecaptchaChallenge(
String challenge,
String captcha
) throws IOException, CaptchaRejectedException {
captcha = captcha == null ? null : captcha.replace("signalcaptcha://", "");
try {
dependencies.getAccountManager().submitRateLimitRecaptchaChallenge(challenge, captcha);
} catch (org.whispersystems.signalservice.api.push.exceptions.CaptchaRejectedException ignored) {
throw new CaptchaRejectedException();
}
}
@Override

View file

@ -5,7 +5,9 @@ import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.CaptchaRejectedException;
import org.asamk.signal.output.OutputWriter;
import java.io.IOException;
@ -38,6 +40,9 @@ public class SubmitRateLimitChallengeCommand implements JsonRpcLocalCommand {
m.submitRateLimitRecaptchaChallenge(challenge, captcha);
} catch (IOException e) {
throw new IOErrorException("Submit challenge error: " + e.getMessage(), e);
} catch (CaptchaRejectedException e) {
throw new UserErrorException(
"Captcha rejected, it may be outdated, already used or solved from a different IP address.");
}
}
}

View file

@ -4,6 +4,7 @@ import org.asamk.Signal;
import org.asamk.signal.BaseConfig;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.AttachmentInvalidException;
import org.asamk.signal.manager.api.CaptchaRejectedException;
import org.asamk.signal.manager.api.DeviceLinkUrl;
import org.asamk.signal.manager.api.GroupId;
import org.asamk.signal.manager.api.GroupInviteLinkUrl;
@ -159,8 +160,10 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
m.submitRateLimitRecaptchaChallenge(challenge, captcha);
} catch (IOException e) {
throw new Error.Failure("Submit challenge error: " + e.getMessage());
} catch (CaptchaRejectedException e) {
throw new Error.Failure(
"Captcha rejected, it may be outdated, already used or solved from a different IP address.");
}
}
@Override