All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hypertrack.net.HyperTrackException Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
package io.hypertrack.net;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * Created by Arjun on 21/04/16.
 */
public class HyperTrackException extends Exception {
    private int statusCode;
    private String message;

    public HyperTrackException(String message, int statusCode) {
        super(message);

        this.message = message;
        this.statusCode = statusCode;
    }

    public static HyperTrackException parseResponse(HttpResponse response) throws IOException {
        try {
            int responseCode = response.getStatusLine().getStatusCode();
            HttpEntity entity = response.getEntity();
            String responseString = EntityUtils.toString(entity, "UTF-8");

            return new HyperTrackException(responseString, responseCode);
        } catch (IOException e) {
            throw new IOException("Unable to decode response");
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy