@Override
 public void onDocumentModified(String resId, String patch) {
   connector.sendPatch(resId, patch);
 }
  private void interpretResponse(Response response, Request request) {
    if (response == null) {
      System.out.println("Failed to interpret response.");
      return;
    }
    if (request instanceof LoginRequest && response.getData() != null) {
      System.out.println("Retrieving user details...");
      Storage.getInstance()
          .setToken(response.getData().getToken()); // set("Token", response.getData().getToken());
      System.out.println("Token: " + Storage.getInstance().getToken()); // get("Token"));
    } else if (request instanceof PullFileRequest && response.getData() != null) {
      documentManager.flushFile(response.getData().getChanges(), response.getData().getBytes());
    } else if (request instanceof FetchProjectsRequest && response.getData() != null) {
      populateProjectData(response.getData().getProjects());
    } else if (request instanceof FetchFilesRequest && response.getData() != null) {
      populateFileData(request.getResId(), response.getData().getFiles());
    } else if (request instanceof SubscribeRequest && response.getStatus() == 1) {
      Storage.getInstance().getUsers().add(Storage.getInstance().getUsername() + " (me)");
    }
    switch (response.getStatus()) {
      case 1:
        return;
      case -100:
        UIManager.showInfoDialog("Error -100", "No such user found.");
        break; // no such user found error
      case -101:
        UIManager.showInfoDialog("Error -101", "Error creating user: internal error.");
        break; // error creating user: internal error
      case -102:
        UIManager.showInfoDialog("Error -102", "Error creating usre: duplicate username.");
        break; // error creating user: duplicate username (reprompt for new username)
      case -103:
        UIManager.showInfoDialog("Error -103", "Error logging in: internal error.");
        break; // error logging in: internal error
      case -104:
        UIManager.showInfoDialog("Error -104", "Error logging in: invalid username or password.");
        break; // error logging in: Invalid Username or Password
      case -105:
        UIManager.showInfoDialog("Error -105", "Error logging in: invalid token.");
        break; // listener.repromptLogin(); Error logging in: Invalid Token

      case -200:
        UIManager.showInfoDialog("Error -200", "No such project found.");
        break; // no such project found
      case -201:
        UIManager.showInfoDialog("Error -201", "Error creating project: internal error.");
        break; // error creating project: internal error
      case -202:
        UIManager.showInfoDialog("Error -202", "Error renaming project: internal error.");
        break; // error renaming project: internal error
      case -203:
        UIManager.showInfoDialog("Error -203", "Error granting permissions: internal error.");
        break; // error granting permissions: internal error
      case -204:
        UIManager.showInfoDialog("Error -204", "Error revoking permissions: internal error.");
        break; // error revoking permissions: internal error
      case -205:
        UIManager.showInfoDialog(
            "Error -205", "Error revoking permissions: document must have an owner.");
        break; // error revoking permissions: must have an owner
      case -206:
        UIManager.showInfoDialog("Error -206", "Error subscribing to project: internal error.");
        break; // error subscribing to project

      case -300:
        UIManager.showInfoDialog("Error -300", "No such file found.");
        break; // no such file found
      case -301:
        UIManager.showInfoDialog("Error -301", "Error creating file: internal error.");
        break; // error creating file: internal error
      case -302:
        UIManager.showInfoDialog("Error -302", "Error renaming file: internal error.");
        break; // error renaming file: internal error
      case -303:
        UIManager.showInfoDialog("Error -303", "Error moving file: internal error.");
        break; // error moving file: internal error
      case -304:
        UIManager.showInfoDialog("Error -304", "Error deleting file: internal error.");
        break; // error deleting file: internal error
      case -305:
        UIManager.showInfoDialog("Error -305", "Error creating file: file already exists.");
        break; // error creating file: duplicate file
      case -306:
        UIManager.showInfoDialog(
            "Error -306", "Error renaming file: file of new name already exists.");
        break; // error renaming file: duplicate file
      case -307:
        UIManager.showInfoDialog(
            "Error -307",
            "Error moving file: file of the same name exists in the target directory.");
        break; // error moving file: duplicate file
      case -308:
        UIManager.showInfoDialog("Error -308", "Error creating file: invalid file path.");
        break; // error creating file: invalid file path

      case -400:
        UIManager.showInfoDialog("Error -400", "Error inserting change: internal error.");
        break; // error inserting change: internal error
      case -401:
        connector.sendPatch(request.getResId(), request.getChanges());
        break; // UIManager.showInfoDialog("Error -401", "Error inserting change: duplicate version
        // number.");break; //error inserting change: duplicate version number
      case -402:
        UIManager.showInfoDialog("Error -402", "Error reading change: internal error.");
        break; // error reading change: internal error
      case -420:
        UIManager.showInfoDialog("Error -420", "Error, too blazed.");
        break; // error, too blazed
    }

    System.out.println("Successfully interpreted response of status: " + response.getStatus());
  }