com.sixestates.exception.RestException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of idp-sdk Show documentation
Show all versions of idp-sdk Show documentation
A Java SDK for communicating with the 6Estates Intelligent Document Processing(IDP) Platform
package com.sixestates.exception;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
/**
* Idp Exceptions.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class RestException {
private final Integer code;
private final String message;
private final String moreInfo;
private final Integer status;
private final Map details;
/**
* Initialize a Idp Rest Exception.
*
* @param status HTTP status code
* @param message message of exception
* @param code Idp status code
* @param moreInfo further information, if there is any
*/
@JsonCreator
private RestException(@JsonProperty("status") final int status, @JsonProperty("message") final String message,
@JsonProperty("code") final Integer code, @JsonProperty("more_info") final String moreInfo,
@JsonProperty("details") final Map details) {
this.status = status;
this.message = message;
this.code = code;
this.moreInfo = moreInfo;
this.details = details;
}
/**
* Build an exception from a JSON blob.
*
* @param json JSON blob
* @param objectMapper JSON reader
* @return Rest Exception as an object
*/
public static RestException fromJson(final InputStream json, final ObjectMapper objectMapper) {
// Convert all checked exception to Runtime
try {
return objectMapper.readValue(json, RestException.class);
} catch (final JsonMappingException | JsonParseException e) {
throw new ApiException(e.getMessage(), e);
} catch (final IOException e) {
throw new ApiConnectionException(e.getMessage(), e);
}
}
public Integer getCode() {
return code;
}
public String getMessage() {
return message;
}
public String getMoreInfo() {
return moreInfo;
}
public Integer getStatus() {
return status;
}
public Map getDetails() {
return details;
}
}