class ApiUtils {

    private static final Logger LOGGER = LoggerFactory.getLogger(ApiUtils.class);

    private static final RuntimeEnvironment env = RuntimeEnvironment.getInstance();

    private ApiUtils() {
        // utility class
    }

    /**
     * Busy waits for API call to complete by repeatedly querying the status API endpoint passed
     * in the {@code Location} header in the response parameter. The overall time is governed
     * by the {@link RuntimeEnvironment#getApiTimeout()}, however each individual status check
     * uses {@link RuntimeEnvironment#getConnectTimeout()} so in the worst case the total time can be
     * {@code getApiTimeout() * getConnectTimeout()}.
     * @param response response returned from the server upon asynchronous API request
     * @return response from the status API call
     * @throws InterruptedException on sleep interruption
     * @throws IllegalArgumentException on invalid request (no {@code Location} header)
     */
    public static @NotNull Response waitForAsyncApi(@NotNull Response response)
            throws InterruptedException, IllegalArgumentException {<FILL_FUNCTION_BODY>}
}


        if (response.getStatus() != Response.Status.ACCEPTED.getStatusCode()) {
            LOGGER.log(Level.WARNING, "API request not accepted: {0}", response);
            return response;
        }

        String location = response.getHeaderString(HttpHeaders.LOCATION);
        if (location == null) {
            throw new IllegalArgumentException(String.format("no %s header in %s", HttpHeaders.LOCATION, response));
        }

        LOGGER.log(Level.FINER, "checking asynchronous API result on {0}", location);
        for (int i = 0; i < env.getApiTimeout(); i++) {
            response = ClientBuilder.newBuilder().
                    connectTimeout(env.getConnectTimeout(), TimeUnit.SECONDS).build().
                    target(location).request().get();
            if (response.getStatus() == Response.Status.ACCEPTED.getStatusCode()) {
                Thread.sleep(1000);
            } else {
                break;
            }
        }

        if (response.getStatus() == Response.Status.ACCEPTED.getStatusCode()) {
            LOGGER.log(Level.WARNING, "API request still not completed: {0}", response);
            return response;
        }

        LOGGER.log(Level.FINER, "making DELETE API request to {0}", location);
        try (Response deleteResponse = ClientBuilder.newBuilder().
                connectTimeout(env.getConnectTimeout(), TimeUnit.SECONDS).build().
                target(location).request().delete()) {
            if (deleteResponse.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
                LOGGER.log(Level.WARNING, "DELETE API call to {0} failed with HTTP error {1}",
                        new Object[]{location, response.getStatusInfo()});
            }
        }

        return response;
    
<no_super_class>