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

com.baidu.discovery.client.exception.ServerStatusException Maven / Gradle / Ivy

package com.baidu.discovery.client.exception;

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * @author Bowu Dong ([email protected])
 */
public class ServerStatusException extends RuntimeException {
    private String message;

    public ServerStatusException(String summary, HttpResponse response) {
        try {
            String body = EntityUtils.toString(response.getEntity());
            String status = response.getStatusLine().toString();
            message = String.format("%s, response=%s(%s)", summary, body, status);
        } catch (IOException e) {
            // omitted exception
        }
    }

    public ServerStatusException(String summary, Object request, HttpResponse response) {
        try {
            String body = EntityUtils.toString(response.getEntity());
            String status = response.getStatusLine().toString();
            message = String.format("%s, request=%s response=%s(%s)", summary, request, body, status);
        } catch (IOException e) {
            // omitted exception
        }
    }

    @Override
    public String getMessage() {
        return message;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy