io.automatiko.addons.fault.tolerance.internal.WrappedTimout Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of automatiko-fault-tolerance-addon Show documentation
Show all versions of automatiko-fault-tolerance-addon Show documentation
Fault Tolerance AddOn for Automatiko Engine
package io.automatiko.addons.fault.tolerance.internal;
import java.util.Collections;
import org.eclipse.microprofile.faulttolerance.exceptions.TimeoutException;
import io.automatiko.engine.api.workflow.ServiceExecutionError;
import io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError;
import io.smallrye.faulttolerance.core.FaultToleranceStrategy;
import io.smallrye.faulttolerance.core.InvocationContext;
public class WrappedTimout implements FaultToleranceStrategy {
private final FaultToleranceStrategy delegate;
public WrappedTimout(FaultToleranceStrategy delegate) {
this.delegate = delegate;
}
@Override
public V apply(InvocationContext ctx) throws Exception {
try {
return delegate.apply(ctx);
} catch (WorkItemExecutionError e) {
throw new ServiceExecutionError(e.getMessage(), e.getErrorCode(), e.getErrorDetails(), e.getErrorData());
} catch (TimeoutException e) {
throw new ServiceExecutionError(e.getMessage(), "408", "timeout occured",
Collections.singletonMap("cause", "timeout reached when invoking service"));
} catch (Throwable e) {
throw new ServiceExecutionError(e.getMessage(), "500", "timeout occured", e);
}
}
}