/** * Executes a YouTrack command and returns a result. * * @return instance of @link CommandResult containing command execution results. */ <O extends BaseItem, R> CommandResult<R> execute(Command<O, R> command) throws CommandExecutionException, IOException { final CloseableHttpClient httpClient = getHttpClient(); try { if (command.usesAuthorization()) { checkAuthState(command); } command.run(httpClient, authorization); final CommandResult<R> result = command.getResult(); if (result.getException() != null) throw result.getException(); if (result.getError() != null) throw new CommandExecutionException(command, result.getError()); return result; } catch (CommandExecutionException cee) { throw cee; } catch (Exception e) { throw new CommandExecutionException(command, e); } finally { command.close(); httpClient.close(); } }