if (browser != null) {
boolean isLast = Boolean.parseBoolean(done);
try {
serviceBrowser(response, isLast, responseId, writer, browser);
} catch (JsonParseException e) {
writer.print(gson.toJson(new JsonCommand(JsonCommand.CommandType.STOP, null)));
writer.flush();
throw new RuntimeException("Unable to parse: " + response, e);
}
} else {
// TODO(corysmith): handle this better.
logger.error("Unknown browser {} with response {}.\n Known {}", new Object[]{id, response, browsers.getSlaveBrowsers()});
writer.print(gson.toJson(new JsonCommand(JsonCommand.CommandType.STOP, Lists.newArrayList("Stopping due to missing browser."))));
try {
Thread.sleep(1000); // pause to make sure the browser doesn't spin.
} catch (InterruptedException e) {
}