Code example for DefaultResponseErrorHandler

0
import org.springframework.social.ResourceNotFoundException; 
import org.springframework.social.foursquare.api.FoursquareApiException; 
import org.springframework.social.foursquare.api.ParamErrorException; 
import org.springframework.web.client.DefaultResponseErrorHandler;
 
public class FoursquareErrorHandler 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("errorType"));
        String message = String.valueOf(errorDetails.get("errorDetail"));
         
        handleFoursquareError(code, errorType, message);
         
        throw new FoursquareApiException(code, errorType, message);		
	}