private <T> T execute(Command<T> cmd) throws Exception { try { SentryGenericServiceClient client = getClient(); try { return cmd.run(client); } finally { client.close(); } } catch (Exception e) { // map sentry exceptions to appropriate cdap-security exceptions if (e instanceof SentryAccessDeniedException) { throw new UnauthorizedException(e.getMessage()); } else if (e instanceof SentryNoSuchObjectException) { throw new NotFoundException(e.getMessage()); } else if (e instanceof SentryAlreadyExistsException) { throw new AlreadyExistsException(e.getMessage()); } else if (e instanceof SentryInvalidInputException || e instanceof SentryThriftAPIMismatchException) { throw new BadRequestException(e.getMessage()); } else { throw e; } } }