Improve addDevice error message

Fixes #1573
This commit is contained in:
AsamK 2024-09-08 09:00:34 +02:00
parent b51f849fe6
commit 19b15e68e4
6 changed files with 30 additions and 6 deletions

View file

@ -7,6 +7,7 @@ import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.DeviceLimitExceededException;
import org.asamk.signal.manager.api.DeviceLinkUrl;
import org.asamk.signal.manager.api.InvalidDeviceLinkException;
import org.asamk.signal.manager.api.NotPrimaryDeviceException;
@ -53,8 +54,10 @@ public class AddDeviceCommand implements JsonRpcLocalCommand {
logger.error("Add device link failed: {}", e.getMessage());
throw new IOErrorException("Add device link failed", e);
} catch (InvalidDeviceLinkException e) {
logger.error("Invalid device link");
logger.info("Invalid device link");
throw new UserErrorException("Invalid device link", e);
} catch (DeviceLimitExceededException e) {
throw new UserErrorException("Account has too many linked devices already", e);
} catch (NotPrimaryDeviceException e) {
throw new UserErrorException("This command doesn't work on linked devices.");
}

View file

@ -5,6 +5,7 @@ import org.asamk.signal.BaseConfig;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.AttachmentInvalidException;
import org.asamk.signal.manager.api.CaptchaRejectedException;
import org.asamk.signal.manager.api.DeviceLimitExceededException;
import org.asamk.signal.manager.api.DeviceLinkUrl;
import org.asamk.signal.manager.api.GroupId;
import org.asamk.signal.manager.api.GroupInviteLinkUrl;
@ -189,7 +190,7 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
try {
var deviceLinkUrl = DeviceLinkUrl.parseDeviceLinkUri(new URI(uri));
m.addDeviceLink(deviceLinkUrl);
} catch (IOException | InvalidDeviceLinkException e) {
} catch (IOException | InvalidDeviceLinkException | DeviceLimitExceededException e) {
throw new Error.Failure(e.getClass().getSimpleName() + " Add device link failed. " + e.getMessage());
} catch (NotPrimaryDeviceException e) {
throw new Error.Failure("This command doesn't work on linked devices.");