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;
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;
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) {
+ String message = "Rate limit reached";
+ if (e.getNextAttemptTimestamp() > 0) {
+ message += "\nNext attempt may be tried at " + DateUtils.formatTimestamp(e.getNextAttemptTimestamp());
+ }
+ throw new RateLimitErrorException(message, e);
} catch (CaptchaRequiredException e) {
String message;
if (captcha == null) {
} 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("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) {}
}