Example usage for java.net HttpRetryException HttpRetryException

List of usage examples for java.net HttpRetryException HttpRetryException

Introduction

In this page you can find the example usage for java.net HttpRetryException HttpRetryException.

Prototype

public HttpRetryException(String detail, int code) 

Source Link

Document

Constructs a new HttpRetryException from the specified response code and exception detail message

Usage

From source file:ai.grakn.client.LoaderClient.java

/**
 * Fetch the status of a single task from the Tasks Controller
 * @param id ID of the task to be fetched
 * @return Json object containing status of the task
 *//*from w w w .j a  v a 2 s  .co  m*/
private Json getStatus(String id) throws HttpRetryException {
    HttpURLConnection connection = null;
    try {
        URL url = new URL(format(GET, uri, id));

        connection = (HttpURLConnection) url.openConnection();
        connection.setDoOutput(true);

        // create post
        connection.setRequestMethod(REST.HttpConn.GET_METHOD);

        if (connection.getResponseCode() == 404) {
            throw new IllegalArgumentException("Not found in Grakn task storage: " + id);
        }

        // get response
        return Json.read(readResponse(connection.getInputStream()));
    } catch (IOException e) {
        throw new HttpRetryException(ErrorMessage.ERROR_COMMUNICATING_TO_HOST.getMessage(uri), 404);
    } finally {
        if (connection != null) {
            connection.disconnect();
        }
    }
}