Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
import io.serverlessworkflow.fluent.spec.BaseTryTaskBuilder;
import java.util.function.Consumer;

public class FuncTryTaskBuilder
extends BaseTryTaskBuilder<FuncTryTaskBuilder, FuncTaskItemListBuilder>
Expand All @@ -32,4 +33,54 @@ public class FuncTryTaskBuilder
protected FuncTryTaskBuilder self() {
return this;
}

/**
* Defines the tasks to execute within the try.
*
* @param tryHandler a consumer that configures the tasks to be executed in the try
* @return this builder instance for method chaining
*/
public FuncTryTaskBuilder tryCatch(Consumer<FuncTaskItemListBuilder> tryHandler) {
return this.tryHandler(tryHandler);
}

/**
* Defines a catch that handles specific errors and executes tasks when those errors occur.
*
* @param catchErrors a consumer that configures which errors to catch (e.g., by type, status
* code)
* @param catchHandler a consumer that configures the tasks to execute when the specified errors
* are caught
* @return this builder instance for method chaining
*/
public FuncTryTaskBuilder catchError(
Consumer<CatchErrorsBuilder> catchErrors, Consumer<FuncTaskItemListBuilder> catchHandler) {
return this.catchHandler(handler -> handler.errorsWith(catchErrors).doTasks(catchHandler));
}

/**
* Defines a conditional catch that executes tasks when a specific condition is met.
*
* @param expr a runtime expression that evaluates to a boolean, determining whether to execute
* the catch handler
* @param catchHandler a consumer that configures the tasks to execute when the condition
* evaluates to true
* @return this builder instance for method chaining
*/
public FuncTryTaskBuilder catchWhen(String expr, Consumer<FuncTaskItemListBuilder> catchHandler) {
return this.catchHandler(handler -> handler.when(expr).doTasks(catchHandler));
}

/**
* Defines a catch that handles errors of a specific type.
*
* @param type the error type to catch (e.g., "java.lang.NullPointerException")
* @param catchHandler a consumer that configures the tasks to execute when an error of the
* specified type is caught
* @return this builder instance for method chaining
*/
public FuncTryTaskBuilder catchType(String type, Consumer<FuncTaskItemListBuilder> catchHandler) {
return this.catchHandler(
handler -> handler.errorsWith(err -> err.type(type)).doTasks(catchHandler));
}
}
Loading
Loading