Add InvalidDeviceLinkException exception

This commit is contained in:
AsamK 2021-10-31 19:35:00 +01:00
parent d783df510a
commit 3cf7721cd7
7 changed files with 54 additions and 25 deletions

View file

@ -6,12 +6,11 @@ import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.InvalidDeviceLinkException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.libsignal.InvalidKeyException;
import java.io.IOException;
import java.net.URI;
@ -38,16 +37,21 @@ public class AddDeviceCommand implements JsonRpcLocalCommand {
public void handleCommand(
final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException {
final URI linkUri;
try {
m.addDeviceLink(new URI(ns.getString("uri")));
linkUri = new URI(ns.getString("uri"));
} catch (URISyntaxException e) {
throw new UserErrorException("Device link uri has invalid format: " + e.getMessage());
}
try {
m.addDeviceLink(linkUri);
} catch (IOException e) {
logger.error("Add device link failed", e);
throw new IOErrorException("Add device link failed", e);
} catch (URISyntaxException e) {
throw new UserErrorException("Device link uri has invalid format: " + e.getMessage());
} catch (InvalidKeyException e) {
} catch (InvalidDeviceLinkException e) {
logger.error("Add device link failed", e);
throw new UnexpectedErrorException("Add device link failed.", e);
throw new UserErrorException("Add device link failed.", e);
}
}
}

View file

@ -10,6 +10,7 @@ import org.asamk.signal.manager.UntrustedIdentityException;
import org.asamk.signal.manager.api.Device;
import org.asamk.signal.manager.api.Group;
import org.asamk.signal.manager.api.Identity;
import org.asamk.signal.manager.api.InvalidDeviceLinkException;
import org.asamk.signal.manager.api.Message;
import org.asamk.signal.manager.api.Pair;
import org.asamk.signal.manager.api.RecipientIdentifier;
@ -31,7 +32,6 @@ import org.freedesktop.dbus.DBusPath;
import org.freedesktop.dbus.connections.impl.DBusConnection;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.interfaces.DBusInterface;
import org.whispersystems.libsignal.InvalidKeyException;
import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
@ -162,7 +162,7 @@ public class DbusManagerImpl implements Manager {
}
@Override
public void addDeviceLink(final URI linkUri) throws IOException, InvalidKeyException {
public void addDeviceLink(final URI linkUri) throws IOException, InvalidDeviceLinkException {
signal.addDevice(linkUri.toString());
}

View file

@ -9,6 +9,7 @@ import org.asamk.signal.manager.NotMasterDeviceException;
import org.asamk.signal.manager.StickerPackInvalidException;
import org.asamk.signal.manager.UntrustedIdentityException;
import org.asamk.signal.manager.api.Identity;
import org.asamk.signal.manager.api.InvalidDeviceLinkException;
import org.asamk.signal.manager.api.Message;
import org.asamk.signal.manager.api.Pair;
import org.asamk.signal.manager.api.RecipientIdentifier;
@ -30,7 +31,6 @@ import org.freedesktop.dbus.connections.impl.DBusConnection;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.exceptions.DBusExecutionException;
import org.freedesktop.dbus.types.Variant;
import org.whispersystems.libsignal.InvalidKeyException;
import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException;
import org.whispersystems.signalservice.api.messages.SendMessageResult;
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
@ -107,7 +107,7 @@ public class DbusSignalImpl implements Signal {
public void addDevice(String uri) {
try {
m.addDeviceLink(new URI(uri));
} catch (IOException | InvalidKeyException e) {
} catch (IOException | InvalidDeviceLinkException e) {
throw new Error.Failure(e.getClass().getSimpleName() + " Add device link failed. " + e.getMessage());
} catch (URISyntaxException e) {
throw new Error.InvalidUri(e.getClass().getSimpleName()