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

How can I config exception num by degradeRule with sentinel-spring-webmvc-adapter #3141

Open
24kpure opened this issue Jun 6, 2023 · 5 comments
Labels
area/circuit-breaking Issues or PRs related to circuit breaking area/integrations Issues or PRs related to integrations with open-source components kind/question Category issues related to questions or problems

Comments

@24kpure
Copy link
Contributor

24kpure commented Jun 6, 2023

com.alibaba.csp.sentinel.adapter.spring.webmvc.AbstractSentinelInterceptor#preHandle can't feel business exception, I config exception num by degradeRule,but it doesn't work.

@bchengwang
Copy link

com.alibaba.csp.sentinel.adapter.spring.webmvc.AbstractSentinelInterceptor#preHandle感觉不到业务异常,我通过degraderRule配置了异常num,但是没有用。

你是不是使用里全局异常处理器?如果使用了全局异常处理器那么异常会被处理器拦截导致AbstractSentinelInterceptor拦截器无法获取到异常信息。

@24kpure
Copy link
Contributor Author

24kpure commented Jun 7, 2023

Nowadays,does it exist that webapplication runs without globalExceptionHandler? I try to extend SentinelWebInterceptor and override mehtod traceExceptionAndExit and make exception visible for sentinel, at last ,it works.

@bchengwang
Copy link

如今,是否存在 webapplication 运行时没有globalExceptionHandler?我尝试扩展 SentinelWebInterceptor和覆盖 mehtodtraceExceptionAndExit并使异常对哨兵可见,最后,它起作用了。

可以发一下你重写的SentinelWebInterceptor的代码吗?让我参考一下。谢谢

@sczyh30 sczyh30 added kind/question Category issues related to questions or problems area/integrations Issues or PRs related to integrations with open-source components area/circuit-breaking Issues or PRs related to circuit breaking labels Jun 7, 2023
@24kpure
Copy link
Contributor Author

24kpure commented Jun 8, 2023

  protected void traceExceptionAndExit(Entry entry, Exception ex) {
        if (entry == null) {
            return;
        }
        if (ex == null) {
            HttpServletRequest httpServletRequest = SerialNoUtils.getHttpServletRequest();
            if (httpServletRequest == null) {
                return;
            }

           // you have to make exception visible for sentinel, my plan is quite simple,just put it into request.
            ex = (Exception) httpServletRequest.getAttribute(requestRefExceptionName);
        }

        if (ex != null) {
            Tracer.traceEntry(ex, entry);
        }
        entry.exit();
    }

@24kpure
Copy link
Contributor Author

24kpure commented Jun 13, 2023

#3149 @bchengwang you can have a try ~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/circuit-breaking Issues or PRs related to circuit breaking area/integrations Issues or PRs related to integrations with open-source components kind/question Category issues related to questions or problems
Projects
None yet
Development

No branches or pull requests

3 participants