mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
parent
af4709255a
commit
56ee173d03
6 changed files with 30 additions and 3 deletions
|
@ -24,6 +24,7 @@ import net.sourceforge.argparse4j.inf.Namespace;
|
|||
|
||||
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.UnexpectedErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UntrustedKeyErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||
|
@ -116,6 +117,8 @@ public class Main {
|
|||
return 3;
|
||||
} else if (e instanceof UntrustedKeyErrorException) {
|
||||
return 4;
|
||||
} else if (e instanceof RateLimitErrorException) {
|
||||
return 5;
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package org.asamk.signal.commands.exceptions;
|
||||
|
||||
import org.asamk.signal.manager.api.RateLimitException;
|
||||
|
||||
public final class RateLimitErrorException extends CommandException {
|
||||
|
||||
public RateLimitErrorException(final String message, final RateLimitException cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
package org.asamk.signal.util;
|
||||
|
||||
import org.asamk.signal.commands.exceptions.CommandException;
|
||||
import org.asamk.signal.commands.exceptions.RateLimitErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UntrustedKeyErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||
import org.asamk.signal.json.JsonSendMessageResult;
|
||||
import org.asamk.signal.manager.api.ProofRequiredException;
|
||||
import org.asamk.signal.manager.api.RateLimitException;
|
||||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||
import org.asamk.signal.manager.api.SendGroupMessageResults;
|
||||
import org.asamk.signal.manager.api.SendMessageResult;
|
||||
|
@ -51,6 +53,9 @@ public class SendMessageResultUtils {
|
|||
if (!sendMessageResults.hasSuccess()) {
|
||||
if (sendMessageResults.hasOnlyUntrustedIdentity()) {
|
||||
throw new UntrustedKeyErrorException("Failed to send message due to untrusted identities");
|
||||
} else if (sendMessageResults.hasOnlyRateLimitFailure()) {
|
||||
throw new RateLimitErrorException("Failed to send message due to rate limiting",
|
||||
new RateLimitException(0));
|
||||
} else {
|
||||
throw new UserErrorException("Failed to send message");
|
||||
}
|
||||
|
@ -111,7 +116,7 @@ public class SendMessageResultUtils {
|
|||
}
|
||||
|
||||
public static void printSendMessageResultErrors(PlainTextWriter writer, List<String> errors) {
|
||||
if (errors.size() == 0) {
|
||||
if (errors.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
writer.println("Failed to send (some) messages:");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue