Code example for DefaultResponseErrorHandler

0
import org.codehaus.jackson.type.TypeReference; 
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.social.instagram.api.InstagramApiException; 
import org.springframework.web.client.DefaultResponseErrorHandler;
 
public class InstagramErrorHandler extends DefaultResponseErrorHandler {
	 
	@Override 
	public void handleError(ClientHttpResponse response) throws IOException {				
	    Map<String, Object> errorDetails = extractErrorDetailsFromResponse(response);
	    int code = Integer.valueOf(String.valueOf(errorDetails.get("code"))).intValue();
        String errorType = String.valueOf(errorDetails.get("error_type"));
        String message = String.valueOf(errorDetails.get("error_message"));
        throw new InstagramApiException(code, errorType, message);		
	} 
	 
	@SuppressWarnings("unchecked") 
    private Map<String, Object> extractErrorDetailsFromResponse(ClientHttpResponse response) throws IOException {
        ObjectMapper mapper = new ObjectMapper(new JsonFactory());
        Map<String, Object> responseMap = mapper.<Map<String, Object>>readValue(response.getBody(), new TypeReference<Map<String, Object>>() {});
Contextual code suggestions in your IDE  Get Codota for Java