]> nmode's Git Repositories - signal-cli/commitdiff
Include proof required information in sending error
authorAsamK <asamk@gmx.de>
Sun, 16 May 2021 14:53:04 +0000 (16:53 +0200)
committerAsamK <asamk@gmx.de>
Sun, 16 May 2021 14:53:04 +0000 (16:53 +0200)
src/main/java/org/asamk/signal/util/ErrorUtils.java

index 100368f6dfa014ee1911eb8382b1ca8738f80157..2442ddb6eb00d1b46f41ce65380cc519657961a6 100644 (file)
@@ -6,9 +6,11 @@ import org.asamk.signal.commands.exceptions.IOErrorException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.whispersystems.signalservice.api.messages.SendMessageResult;
+import org.whispersystems.signalservice.api.push.exceptions.ProofRequiredException;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 public class ErrorUtils {
 
@@ -46,6 +48,17 @@ public class ErrorUtils {
             return String.format("Unregistered user \"%s\"", result.getAddress().getLegacyIdentifier());
         } else if (result.getIdentityFailure() != null) {
             return String.format("Untrusted Identity for \"%s\"", result.getAddress().getLegacyIdentifier());
+        } else if (result.getProofRequiredFailure() != null) {
+            final var failure = result.getProofRequiredFailure();
+            return String.format(
+                    "CAPTCHA proof required for sending to \"%s\", available options \"%s\" with token \"%s\", or wait \"%d\" seconds",
+                    result.getAddress().getLegacyIdentifier(),
+                    failure.getOptions()
+                            .stream()
+                            .map(ProofRequiredException.Option::toString)
+                            .collect(Collectors.joining(", ")),
+                    failure.getToken(),
+                    failure.getRetryAfterSeconds());
         }
         return null;
     }