]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/RegisterCommand.java
Implement editing of previous messages
[signal-cli] / src / main / java / org / asamk / signal / commands / RegisterCommand.java
index 4415bb1812006cf39ca2217a1632c01072d9be0d..5ba66d7a6c98991a0410bbfbc9624edfcc529a0f 100644 (file)
@@ -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,6 +67,12 @@ 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) {
@@ -76,11 +84,15 @@ public class RegisterCommand implements RegistrationCommand, JsonRpcRegistration
             } 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: " + e.getMessage(), e);
         }
     }