mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Print more detailed error message when registering with non-normalized number
Fixes #958
This commit is contained in:
parent
cf07512d24
commit
995eaa6e7c
7 changed files with 35 additions and 4 deletions
|
@ -2,6 +2,7 @@ package org.asamk.signal.manager;
|
|||
|
||||
import org.asamk.signal.manager.api.CaptchaRequiredException;
|
||||
import org.asamk.signal.manager.api.IncorrectPinException;
|
||||
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
||||
import org.asamk.signal.manager.api.PinLockedException;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
@ -9,7 +10,9 @@ import java.io.IOException;
|
|||
|
||||
public interface RegistrationManager extends Closeable {
|
||||
|
||||
void register(boolean voiceVerification, String captcha) throws IOException, CaptchaRequiredException;
|
||||
void register(
|
||||
boolean voiceVerification, String captcha
|
||||
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException;
|
||||
|
||||
void verifyAccount(
|
||||
String verificationCode, String pin
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.asamk.signal.manager;
|
|||
|
||||
import org.asamk.signal.manager.api.CaptchaRequiredException;
|
||||
import org.asamk.signal.manager.api.IncorrectPinException;
|
||||
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
||||
import org.asamk.signal.manager.api.PinLockedException;
|
||||
import org.asamk.signal.manager.api.UpdateProfile;
|
||||
import org.asamk.signal.manager.config.ServiceConfig;
|
||||
|
@ -95,7 +96,9 @@ class RegistrationManagerImpl implements RegistrationManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void register(boolean voiceVerification, String captcha) throws IOException, CaptchaRequiredException {
|
||||
public void register(
|
||||
boolean voiceVerification, String captcha
|
||||
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException {
|
||||
if (account.isRegistered()
|
||||
&& account.getServiceEnvironment() != null
|
||||
&& account.getServiceEnvironment() != serviceEnvironmentConfig.getType()) {
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package org.asamk.signal.manager.api;
|
||||
|
||||
public class NonNormalizedPhoneNumberException extends Exception {
|
||||
|
||||
public NonNormalizedPhoneNumberException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public NonNormalizedPhoneNumberException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import org.asamk.signal.manager.SignalDependencies;
|
|||
import org.asamk.signal.manager.api.CaptchaRequiredException;
|
||||
import org.asamk.signal.manager.api.IncorrectPinException;
|
||||
import org.asamk.signal.manager.api.InvalidDeviceLinkException;
|
||||
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
||||
import org.asamk.signal.manager.api.PinLockedException;
|
||||
import org.asamk.signal.manager.config.ServiceConfig;
|
||||
import org.asamk.signal.manager.storage.SignalAccount;
|
||||
|
@ -95,7 +96,7 @@ public class AccountHelper {
|
|||
|
||||
public void startChangeNumber(
|
||||
String newNumber, String captcha, boolean voiceVerification
|
||||
) throws IOException, CaptchaRequiredException {
|
||||
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException {
|
||||
final var accountManager = dependencies.createUnauthenticatedAccountManager(newNumber, account.getPassword());
|
||||
NumberVerificationUtils.requestVerificationCode(accountManager, captcha, voiceVerification);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.asamk.signal.manager.util;
|
|||
|
||||
import org.asamk.signal.manager.api.CaptchaRequiredException;
|
||||
import org.asamk.signal.manager.api.IncorrectPinException;
|
||||
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
||||
import org.asamk.signal.manager.api.Pair;
|
||||
import org.asamk.signal.manager.api.PinLockedException;
|
||||
import org.asamk.signal.manager.helper.PinHelper;
|
||||
|
@ -20,7 +21,7 @@ public class NumberVerificationUtils {
|
|||
|
||||
public static void requestVerificationCode(
|
||||
SignalServiceAccountManager accountManager, String captcha, boolean voiceVerification
|
||||
) throws IOException, CaptchaRequiredException {
|
||||
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException {
|
||||
captcha = captcha == null ? null : captcha.replace("signalcaptcha://", "");
|
||||
|
||||
final ServiceResponse<RequestVerificationCodeResponse> response;
|
||||
|
@ -39,6 +40,11 @@ public class NumberVerificationUtils {
|
|||
handleResponseException(response);
|
||||
} catch (org.whispersystems.signalservice.api.push.exceptions.CaptchaRequiredException e) {
|
||||
throw new CaptchaRequiredException(e.getMessage(), e);
|
||||
} catch (org.whispersystems.signalservice.api.push.exceptions.NonNormalizedPhoneNumberException e) {
|
||||
throw new NonNormalizedPhoneNumberException("Phone number is not normalized ("
|
||||
+ e.getMessage()
|
||||
+ "). Expected normalized: "
|
||||
+ e.getNormalizedNumber(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.asamk.signal.commands.exceptions.IOErrorException;
|
|||
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.output.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -76,6 +77,8 @@ public class RegisterCommand implements RegistrationCommand, JsonRpcRegistration
|
|||
message = "Invalid captcha given.";
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.asamk.signal.manager.ProvisioningManager;
|
|||
import org.asamk.signal.manager.RegistrationManager;
|
||||
import org.asamk.signal.manager.api.CaptchaRequiredException;
|
||||
import org.asamk.signal.manager.api.IncorrectPinException;
|
||||
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
||||
import org.asamk.signal.manager.api.PinLockedException;
|
||||
import org.asamk.signal.manager.api.UserAlreadyExistsException;
|
||||
import org.freedesktop.dbus.DBusPath;
|
||||
|
@ -61,6 +62,8 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl {
|
|||
} catch (CaptchaRequiredException e) {
|
||||
String message = captcha == null ? "Captcha required for verification." : "Invalid captcha given.";
|
||||
throw new SignalControl.Error.RequiresCaptcha(message);
|
||||
} catch (NonNormalizedPhoneNumberException e) {
|
||||
throw new Error.InvalidNumber(e.getMessage());
|
||||
} catch (OverlappingFileLockException e) {
|
||||
throw new SignalControl.Error.Failure("Account is already in use");
|
||||
} catch (IOException e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue