Code example for DefaultResponseErrorHandler

0
/** 
 * Custom error handler for handling Salesforce API specific error responses. 
 * 
 * @author Umut Utkan 
 */ 
public class ErrorHandler extends DefaultResponseErrorHandler {
 
    @Override 
    public void handleError(ClientHttpResponse response) throws IOException {
        if (response.getStatusCode().equals(HttpStatus.BAD_REQUEST)) {
            Map<String, String> error = extractErrorDetailsFromResponse(response);
            if ("unsupported_response_type".equals(error.get("error"))) {
                throw new OperationNotPermittedException(error.get("error_description"));
            } else if ("invalid_client_id".equals(error.get("error"))) {
                throw new InvalidAuthorizationException(error.get("error_description"));
            } else if ("invalid_request".equals(error.get("error"))) {
                throw new OperationNotPermittedException(error.get("error_description"));
            } else if ("invalid_client_credentials".equals(error.get("error"))) {
                throw new InvalidAuthorizationException(error.get("error_description"));
            } else if ("invalid_grant".equals(error.get("error"))) {