Print more detailed error message when registering with non-normalized number

Fixes #958
This commit is contained in:
AsamK 2022-05-22 22:01:11 +02:00
parent cf07512d24
commit 995eaa6e7c
7 changed files with 35 additions and 4 deletions

View file

@ -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

View file

@ -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()) {

View file

@ -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);
}
}

View file

@ -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);
}

View file

@ -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);
}
}