Improve error message when an account is already in use

This commit is contained in:
AsamK 2021-12-05 12:00:49 +01:00
parent c8b9ab1911
commit 6c1013b024
2 changed files with 9 additions and 0 deletions

View file

@ -15,6 +15,7 @@ import org.freedesktop.dbus.DBusPath;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.nio.channels.OverlappingFileLockException;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -60,6 +61,8 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl {
} catch (CaptchaRequiredException e) { } catch (CaptchaRequiredException e) {
String message = captcha == null ? "Captcha required for verification." : "Invalid captcha given."; String message = captcha == null ? "Captcha required for verification." : "Invalid captcha given.";
throw new SignalControl.Error.RequiresCaptcha(message); throw new SignalControl.Error.RequiresCaptcha(message);
} catch (OverlappingFileLockException e) {
throw new SignalControl.Error.Failure("Account is already in use");
} catch (IOException e) { } catch (IOException e) {
throw new SignalControl.Error.Failure(e.getClass().getSimpleName() + " " + e.getMessage()); throw new SignalControl.Error.Failure(e.getClass().getSimpleName() + " " + e.getMessage());
} }
@ -76,6 +79,8 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl {
) throws Error.Failure, Error.InvalidNumber { ) throws Error.Failure, Error.InvalidNumber {
try (final RegistrationManager registrationManager = c.getNewRegistrationManager(number)) { try (final RegistrationManager registrationManager = c.getNewRegistrationManager(number)) {
registrationManager.verifyAccount(verificationCode, pin); registrationManager.verifyAccount(verificationCode, pin);
} catch (OverlappingFileLockException e) {
throw new SignalControl.Error.Failure("Account is already in use");
} catch (IOException | PinLockedException | IncorrectPinException e) { } catch (IOException | PinLockedException | IncorrectPinException e) {
throw new SignalControl.Error.Failure(e.getClass().getSimpleName() + " " + e.getMessage()); throw new SignalControl.Error.Failure(e.getClass().getSimpleName() + " " + e.getMessage());
} }

View file

@ -27,6 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.nio.channels.OverlappingFileLockException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -182,6 +183,9 @@ public class SignalJsonRpcDispatcherHandler {
final var registrationManager = c.getNewRegistrationManager(params.get("account").asText()); final var registrationManager = c.getNewRegistrationManager(params.get("account").asText());
((ObjectNode) params).remove("account"); ((ObjectNode) params).remove("account");
return registrationManager; return registrationManager;
} catch (OverlappingFileLockException e) {
logger.warn("Account is already in use");
return null;
} catch (IOException | IllegalStateException e) { } catch (IOException | IllegalStateException e) {
logger.warn("Failed to load registration manager", e); logger.warn("Failed to load registration manager", e);
return null; return null;