|
15 | 15 | */ |
16 | 16 | package org.cufy.http.pipeline.wrapper; |
17 | 17 |
|
18 | | -import org.cufy.http.pipeline.Interceptor; |
19 | | -import org.cufy.http.pipeline.Middleware; |
20 | | -import org.cufy.http.pipeline.Next; |
21 | | -import org.cufy.http.pipeline.Pipe; |
| 18 | +import org.cufy.http.pipeline.*; |
22 | 19 | import org.jetbrains.annotations.Contract; |
23 | 20 | import org.jetbrains.annotations.NotNull; |
24 | 21 |
|
|
35 | 32 | */ |
36 | 33 | public interface PipelineContext<T, Self extends PipelineContext<T, Self>> extends |
37 | 34 | NextWrapper<T, Self>, PipeWrapper<T, Self> { |
| 35 | + /** |
| 36 | + * <h3>After Pipeline</h3> |
| 37 | + * Replace the current next function with a new next function from combining the |
| 38 | + * current next function and the given {@code catcher} function. |
| 39 | + * <br> |
| 40 | + * Unlike the pipe, the next function is always the last thing been executed (after |
| 41 | + * the pipeline finishes executing). The provided catcher function will be combined |
| 42 | + * with the current next function (the current next function first then the function |
| 43 | + * provided). When combining two next functions, each function cannot interrupt the |
| 44 | + * other (unless an exception is thrown). So, be careful. The next function is |
| 45 | + * intended to be for cleanup purposes and exception handling. Do not handle the |
| 46 | + * request/response itself in it. |
| 47 | + * |
| 48 | + * @param catcher the catcher function to be used. |
| 49 | + * @return this. |
| 50 | + * @throws NullPointerException if the given {@code catcher} is null. |
| 51 | + * @since 1.0.0 ~2022.01.09 |
| 52 | + */ |
| 53 | + @NotNull |
| 54 | + @Contract(value = "_->this", mutates = "this") |
| 55 | + default Self handle(@NotNull Catcher<T> catcher) { |
| 56 | + Objects.requireNonNull(catcher, "catcher"); |
| 57 | + return this.next(n -> { |
| 58 | + return Next.combine(n, catcher); |
| 59 | + }); |
| 60 | + } |
| 61 | + |
38 | 62 | /** |
39 | 63 | * <h3>Right away</h3> |
40 | 64 | * Inject the given {@code middleware} to this. |
|
0 commit comments