Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spring cloud alibaba 2022.0.0.0-RC1版本,sentine控制台设置系统规则,走了规则,但是统一异常处理未能捕获异常,是怎么回事? #3932

Open
liuyu28 opened this issue Dec 28, 2024 · 0 comments

Comments

@liuyu28
Copy link

liuyu28 commented Dec 28, 2024

1、配置了系统规则
image

2、增加了统一异常处理
`@Component
public class MyBlockExceptionHandler implements BlockExceptionHandler {
private static final Logger log = LoggerFactory.getLogger(MyBlockExceptionHandler.class);

@Override
public void handle(HttpServletRequest httpServletRequest, HttpServletResponse response, BlockException e) throws Exception {
    log.info("=====MyBlockExceptionHandler=====");
    Result r = null;
    if (e instanceof FlowException) {
        r = Result.error(100, "限流了");
    } else if (e instanceof DegradeException) {
        r = Result.error(101, "降级了");
    } else if (e instanceof ParamFlowException) {
        r = Result.error(102, "热点参数限流了");
    } else if (e instanceof SystemBlockException) {
        r = Result.error(103, "触发系统保护机制了");
    } else if (e instanceof AuthorityException) {
        r = Result.error(104, "授权规则不通过");
    }

    //返回json数据
    response.setStatus(500);
    response.setCharacterEncoding("utf-8");
    response.setContentType("application/json;charset=utf-8");
    new ObjectMapper().writeValue(response.getWriter(), r);
}

}`

3、测试查看实时监控,发现确实按照规则QPS通过了2,但是降级处理一直没有走
image

按照异常统一处理逻辑,应该返回"触发系统保护机制了",但是接口一直正常返回,请问会是什么原因导致?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant