diff --git a/_solon_extend/solon.auth/src/test/java/demo1/DemoFilter.java b/_solon_extend/solon.auth/src/test/java/demo1/DemoFilter.java new file mode 100644 index 0000000000..0a6902c6e9 --- /dev/null +++ b/_solon_extend/solon.auth/src/test/java/demo1/DemoFilter.java @@ -0,0 +1,25 @@ +package demo1; + +import org.noear.solon.annotation.Component; +import org.noear.solon.auth.AuthException; +import org.noear.solon.auth.AuthStatus; +import org.noear.solon.core.handle.Context; +import org.noear.solon.core.handle.Filter; +import org.noear.solon.core.handle.FilterChain; +import org.noear.solon.core.handle.Result; + +/** + * @author noear 2022/9/28 created + */ +@Component +public class DemoFilter implements Filter { + @Override + public void doFilter(Context ctx, FilterChain chain) throws Throwable { + try { + chain.doFilter(ctx); + } catch (AuthException e) { + AuthStatus status = e.getStatus(); + ctx.render(Result.failure(status.code, status.message)); + } + } +} diff --git a/_solon_extend/solon.validation/src/test/java/demo1/DemoFilter.java b/_solon_extend/solon.validation/src/test/java/demo1/DemoFilter.java new file mode 100644 index 0000000000..344c0212ee --- /dev/null +++ b/_solon_extend/solon.validation/src/test/java/demo1/DemoFilter.java @@ -0,0 +1,24 @@ +package demo1; + +import org.noear.solon.annotation.Component; +import org.noear.solon.core.handle.Context; +import org.noear.solon.core.handle.Filter; +import org.noear.solon.core.handle.FilterChain; +import org.noear.solon.core.handle.Result; +import org.noear.solon.validation.ValidatorException; + + +/** + * @author noear 2022/9/28 created + */ +@Component +public class DemoFilter implements Filter { + @Override + public void doFilter(Context ctx, FilterChain chain) throws Throwable { + try { + chain.doFilter(ctx); + } catch (ValidatorException e) { + ctx.render(Result.failure(e.getCode(), e.getMessage())); + } + } +}