com.sumologic.client.SumoServerException Maven / Gradle / Ivy
package com.sumologic.client;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sumologic.client.util.JacksonUtils;
import java.util.Map;
/**
* A sumo server-side exception comprising the HTTP status code,
* error identifier and code, the query uri used and a human-readable
* message.
*
* @author Sebastian Mies
* @author Daphne Hsieh
*/
public class SumoServerException extends SumoException {
private String uri;
private int status;
// (message, id, code) == null if the server doesn't respond with a nice JSON
private String message;
private String id;
private String code;
/**
* Constructs a server exception when a JSON error message is not available.
*
* @param uri The URI that caused the exception
* @param status The HTTP status
*/
public SumoServerException(String uri, int status) {
super("The server responded with HTTP Status: " + status);
this.uri = uri;
this.status = status;
this.message = null;
this.id = null;
this.code = null;
}
/**
* Constructs a server exception from a JSON error message
*
* @param uri The URI that caused the exception
* @param json The JSON error message
* @throws SumoClientException Thrown if the JSON error message contains syntactic errors.
*/
public SumoServerException(String uri, String json) throws SumoClientException {
super(json);
this.uri = uri;
// Parse JSON string
try {
Map kv = JacksonUtils.MAPPER.readValue(json,
new TypeReference