- throw new UserErrorException("Device link uri has invalid format: {}" + e.getMessage());
- } catch (InvalidKeyException e) {
- logger.error("Add device link failed", e);
- throw new UnexpectedErrorException("Add device link failed.");
- } catch (AssertionError e) {
- handleAssertionError(e);
- throw e;
+ throw new UserErrorException("Device link uri has invalid format: " + e.getMessage());
+ }
+
+ try {
+ var deviceLinkUrl = DeviceLinkUrl.parseDeviceLinkUri(linkUri);
+ m.addDeviceLink(deviceLinkUrl);
+ } catch (IOException e) {
+ logger.error("Add device link failed: {}", e.getMessage());
+ throw new IOErrorException("Add device link failed", e);
+ } catch (InvalidDeviceLinkException e) {
+ logger.error("Invalid device link");
+ throw new UserErrorException("Invalid device link", e);
+ } catch (NotPrimaryDeviceException e) {
+ throw new UserErrorException("This command doesn't work on linked devices.");