]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/RegisterCommand.java
Implement exit code for rate limiting error
[signal-cli] / src / main / java / org / asamk / signal / commands / RegisterCommand.java
index 5ba66d7a6c98991a0410bbfbc9624edfcc529a0f..1ca7bee2c1e20c94e54b086585f2280ee7337708 100644 (file)
@@ -9,6 +9,7 @@ import net.sourceforge.argparse4j.inf.Subparser;
 import org.asamk.signal.OutputType;
 import org.asamk.signal.commands.exceptions.CommandException;
 import org.asamk.signal.commands.exceptions.IOErrorException;
+import org.asamk.signal.commands.exceptions.RateLimitErrorException;
 import org.asamk.signal.commands.exceptions.UserErrorException;
 import org.asamk.signal.manager.RegistrationManager;
 import org.asamk.signal.manager.api.CaptchaRequiredException;
@@ -64,7 +65,7 @@ public class RegisterCommand implements RegistrationCommand, JsonRpcRegistration
 
     private void register(
             final RegistrationManager m, final boolean voiceVerification, final String captcha
-    ) throws UserErrorException, IOErrorException {
+    ) throws CommandException {
         try {
             m.register(voiceVerification, captcha);
         } catch (RateLimitException e) {
@@ -72,7 +73,7 @@ public class RegisterCommand implements RegistrationCommand, JsonRpcRegistration
             if (e.getNextAttemptTimestamp() > 0) {
                 message += "\nNext attempt may be tried at " + DateUtils.formatTimestamp(e.getNextAttemptTimestamp());
             }
-            throw new UserErrorException(message);
+            throw new RateLimitErrorException(message, e);
         } catch (CaptchaRequiredException e) {
             String message;
             if (captcha == null) {
@@ -92,9 +93,10 @@ public class RegisterCommand implements RegistrationCommand, JsonRpcRegistration
         } catch (NonNormalizedPhoneNumberException e) {
             throw new UserErrorException("Failed to register: " + e.getMessage(), e);
         } catch (IOException e) {
-            throw new IOErrorException("Failed to register: " + 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) {}
 }