com.afrozaar.wordpress.wpapi.v2.exception.ParsedRestException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wp-api-v2-client-java Show documentation
Show all versions of wp-api-v2-client-java Show documentation
A Java client implementation to the WordPress WP-API v2 plugin.
package com.afrozaar.wordpress.wpapi.v2.exception;
import org.springframework.web.client.HttpStatusCodeException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
public class ParsedRestException {
private static final String FIELD_CODE = "code";
private static final String FIELD_MESSAGE = "message";
private static final String FIELD_DATA = "data";
private static final String FIELD_ADDITIONAL_ERRORS = "additional_errors";
private static ObjectMapper mapper;
private final String code;
private final String errorMessage;
private final Object data;
private final HttpStatusCodeException cause;
private final Collection additionalErrors;
private ParsedRestException(HttpStatusCodeException cause, String code, String errorMessage, Object data, Collection additionalErrors) {
this.cause = cause;
this.code = code;
this.errorMessage = errorMessage;
this.data = data;
this.additionalErrors = additionalErrors;
}
static class RestException {
private final String code;
private final String message;
private final Object data;
public static RestException fromRaw(Object mapObject) {
final Map errorMap = (Map) mapObject;
final String code = (String) errorMap.get(FIELD_CODE);
final String message = (String) errorMap.get(FIELD_MESSAGE);
final Object data = errorMap.get(FIELD_DATA);
return new RestException(code, message, data);
}
RestException(String code, String message, Object data) {
this.code = code;
this.message = message;
this.data = data;
}
public String getCode() {
return code;
}
public String getMessage() {
return message;
}
public Object getData() {
return data;
}
@Override
public String toString() {
final StringBuffer sb = new StringBuffer("RestException{");
sb.append("code='").append(code).append('\'');
sb.append(", message='").append(message).append('\'');
sb.append(", data=").append(data);
sb.append('}');
return sb.toString();
}
}
@SuppressWarnings("unchecked")
private static final Function
© 2015 - 2024 Weber Informatics LLC | Privacy Policy