diff --git a/java/core/src/main/java/ws/epigraph/assembly/Asm.java b/java/core/src/main/java/ws/epigraph/assembly/Asm.java index 7075cbea7..38e1daeb2 100644 --- a/java/core/src/main/java/ws/epigraph/assembly/Asm.java +++ b/java/core/src/main/java/ws/epigraph/assembly/Asm.java @@ -56,25 +56,14 @@ public interface Asm { return (dto, projection, ctx) -> assemble(f.apply(dto), projection, ctx); } - /** - * Composes a function {@code f} with an assembler by applying {@code f} to the data object - * before {@code assemble} call. Ideologically it would be similar to {@code f.andThen(this)} - * - * @param f function to run on the data object - * @param ef function to be called if {@code f} application produces an error - * @param new data object type - * - * @return composed assembler - */ - default @NotNull Asm from(@NotNull Function f, @NotNull Function ef) { + // parameterize on exception class? + default @NotNull Asm catching(@NotNull Function handler) { return (dto, projection, ctx) -> { - D d; try { - d = f.apply(dto); - } catch (Exception ex) { - return ef.apply(ex); + return assemble(dto, projection, ctx); + } catch (Exception e) { + return handler.apply(e); } - return assemble(d, projection, ctx); }; }