package cn.axzo.workflow.starter.handler.execute.interceptor;

import cn.axzo.workflow.starter.common.exception.WorkflowListenerExeException;
import cn.axzo.workflow.starter.handler.execute.ListenerExecutor;

import java.util.function.Consumer;

/**
 * 快速失败，出错直接抛出异常，listener不再往下执行
 */
public final class FailFastInterceptor extends AbstractListenerInterceptor {

    @Override
    public <T> void execute(ListenerExecutor executor, Consumer<T> consumer, T t) {
        try {
            getNext().execute(executor, consumer, t);
        } catch (Exception e) {
            throw new WorkflowListenerExeException(
                    "Failed to invoke the method "
//                            + methodName
                            + ". Last error is: " + e.getMessage(), e.getCause() != null ? e.getCause() : e);
        }
    }

}
