X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/995eaa6e7cb49b353e306adf08c0457e1aade618..ac815f759820a9e91cd1857159972ea8a106dbff:/src/main/java/org/asamk/signal/commands/RegisterCommand.java diff --git a/src/main/java/org/asamk/signal/commands/RegisterCommand.java b/src/main/java/org/asamk/signal/commands/RegisterCommand.java index b2d3581e..5018b7e0 100644 --- a/src/main/java/org/asamk/signal/commands/RegisterCommand.java +++ b/src/main/java/org/asamk/signal/commands/RegisterCommand.java @@ -13,7 +13,9 @@ import org.asamk.signal.commands.exceptions.UserErrorException; import org.asamk.signal.manager.RegistrationManager; import org.asamk.signal.manager.api.CaptchaRequiredException; import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException; +import org.asamk.signal.manager.api.RateLimitException; import org.asamk.signal.output.JsonWriter; +import org.asamk.signal.util.DateUtils; import java.io.IOException; import java.util.List; @@ -65,24 +67,35 @@ public class RegisterCommand implements RegistrationCommand, JsonRpcRegistration ) throws UserErrorException, IOErrorException { try { m.register(voiceVerification, captcha); + } catch (RateLimitException e) { + String message = "Rate limit reached"; + if (e.getNextAttemptTimestamp() > 0) { + message += "\nNext attempt may be tried at " + DateUtils.formatTimestamp(e.getNextAttemptTimestamp()); + } + throw new UserErrorException(message); } catch (CaptchaRequiredException e) { String message; if (captcha == null) { message = """ - Captcha required for verification, use --captcha CAPTCHA - To get the token, go to https://signalcaptchas.org/registration/generate.html - Check the developer tools (F12) console for a failed redirect to signalcaptcha:// - Everything after signalcaptcha:// is the captcha token."""; + Captcha required for verification, use --captcha CAPTCHA + To get the token, go to https://signalcaptchas.org/registration/generate.html + Check the developer tools (F12) console for a failed redirect to signalcaptcha:// + Everything after signalcaptcha:// is the captcha token."""; } else { message = "Invalid captcha given."; } + if (e.getNextAttemptTimestamp() > 0) { + message += "\nNext Captcha may be provided at " + + DateUtils.formatTimestamp(e.getNextAttemptTimestamp()); + } throw new UserErrorException(message); } catch (NonNormalizedPhoneNumberException e) { throw new UserErrorException("Failed to register: " + e.getMessage(), e); } catch (IOException e) { - throw new IOErrorException("Request verify error: " + e.getMessage(), e); + throw new IOErrorException("Failed to register: %s (%s)".formatted(e.getMessage(), + e.getClass().getSimpleName()), e); } } - record RegistrationParams(Boolean voice, String captcha) {} + public record RegistrationParams(Boolean voice, String captcha) {} }