-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
_solon_extend/solon.auth/src/test/java/demo1/DemoFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
_solon_extend/solon.validation/src/test/java/demo1/DemoFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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())); | ||
} | ||
} | ||
} |