- public int handleCommand(final Namespace ns, final Manager m) {
- if (!m.isRegistered()) {
- System.err.println("User is not registered.");
- return 1;
+ public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
+ var number = ns.getString("number");
+
+ try {
+ var expiration = ns.getInt("expiration");
+ if (expiration != null) {
+ m.setExpirationTimer(number, expiration);
+ }
+
+ var name = ns.getString("name");
+ if (name != null) {
+ m.setContactName(number, name);
+ }
+ } catch (InvalidNumberException e) {
+ throw new UserErrorException("Invalid contact number: " + e.getMessage());
+ } catch (IOException e) {
+ throw new IOErrorException("Update contact error: " + e.getMessage());
+ } catch (NotMasterDeviceException e) {
+ throw new UserErrorException("This command doesn't work on linked devices.");