@Override
    protected CompletableFuture<EmptyResponseBody> handleRequest(
            @Nonnull final HandlerRequest<EmptyRequestBody> request,
            @Nonnull final RestfulGateway gateway)
            throws RestHandlerException {

        final String jarId = request.getPathParameter(JarIdPathParameter.class);
        return CompletableFuture.supplyAsync(
                () -> {
                    final Path jarToDelete = jarDir.resolve(jarId);
                    if (!Files.exists(jarToDelete)) {
                        throw new CompletionException(
                                new RestHandlerException(
                                        String.format(
                                                "File %s does not exist in %s.", jarId, jarDir),
                                        HttpResponseStatus.BAD_REQUEST));
                    } else {
                        try {
                            Files.delete(jarToDelete);
                            return EmptyResponseBody.getInstance();
                        } catch (final IOException e) {
                            throw new CompletionException(
                                    new RestHandlerException(
                                            String.format("Failed to delete jar %s.", jarToDelete),
                                            HttpResponseStatus.INTERNAL_SERVER_ERROR,
                                            e));
                        }
                    }
                },
                executor);
    }
@Tag("org.apache.flink.testutils.junit.FailsInGHAContainerWithRootUser")
    @Test
    void testFailedDelete() throws Exception {
        makeJarDirReadOnly();

        final HandlerRequest<EmptyRequestBody> request = createRequest(TEST_JAR_NAME);
        assertThatThrownBy(() -> jarDeleteHandler.handleRequest(request, restfulGateway).get())
                .satisfies(
                        e -> {
                            final Throwable throwable =
                                    ExceptionUtils.stripCompletionException(e.getCause());
                            assertThat(throwable).isInstanceOf(RestHandlerException.class);

                            final RestHandlerException restHandlerException =
                                    (RestHandlerException) throwable;
                            assertThat(restHandlerException.getMessage())
                                    .contains("Failed to delete jar");
                            assertThat(restHandlerException.getHttpResponseStatus())
                                    .isEqualTo(HttpResponseStatus.INTERNAL_SERVER_ERROR);
                        });
    }