All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.giffing.bucket4j.spring.boot.starter.config.failureanalyzer.Bucket4JAutoConfigFailureAnalyzer Maven / Gradle / Ivy

There is a newer version: 0.12.7
Show newest version
package com.giffing.bucket4j.spring.boot.starter.config.failureanalyzer;

import com.giffing.bucket4j.spring.boot.starter.exception.Bucket4jGeneralException;
import com.giffing.bucket4j.spring.boot.starter.exception.ExecutePredicateInstantiationException;
import com.giffing.bucket4j.spring.boot.starter.exception.JCacheNotFoundException;
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
import org.springframework.boot.diagnostics.FailureAnalysis;

/**
 * The failure analyzer is responsible to provide readable information of exception which
 * occur on startup. All exception based on the {@link Bucket4jGeneralException} are handled here.   
 */
public class Bucket4JAutoConfigFailureAnalyzer extends AbstractFailureAnalyzer{

	public static final String NEW_LINE = System.getProperty("line.separator");
	
	@Override
	protected FailureAnalysis analyze(Throwable rootFailure, Bucket4jGeneralException cause) {
		String descriptionMessage = cause.getMessage();
		String actionMessage = cause.getMessage();
		
		if(cause instanceof JCacheNotFoundException e) {
			descriptionMessage = e.getMessage();
			actionMessage = "Cache name: " + e.getCacheName() + NEW_LINE
					+ "Please configure your caching provider (ehcache, hazelcast, ...)";
		}
		
		if (cause instanceof ExecutePredicateInstantiationException e) {
			descriptionMessage = e.getMessage();
			actionMessage = "Please provide a default constructor.";
		}
		
		return new FailureAnalysis(descriptionMessage, actionMessage, cause);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy