在 python 中很简单,您只需在配置文件中添加以下代码即可忽略多个异常
ignore_exceptions = [
'Http404',
'Http401'
'django.exceptions.http.Http404',
'django.exceptions.*',
ValueError,
]
但是在java中我在sentry.properties中找不到类似的标签,你自己试试也许你会找到。
##Just give it a try, I didnt test
ignore.exceptions:
HTTP 401
或您可以在配置类中添加HandlerExceptionResolver 并覆盖resolveException 方法并手动忽略异常。
@Configuration
public class FactoryBeanAppConfig {
@Bean
public HandlerExceptionResolver sentryExceptionResolver() {
return new SentryExceptionResolver() {
@Override
public ModelAndView resolveException(HttpServletRequest request,
HttpServletResponse response,
Object handler,
Exception ex) {
Throwable rootCause = ex;
while (rootCause .getCause() != null && rootCause.getCause() != rootCause) {
rootCause = rootCause.getCause();
}
if (!rootCause.getMessage().contains("HTTP 401")) {
super.resolveException(request, response, handler, ex);
}
return null;
}
};
}
@Bean
public ServletContextInitializer sentryServletContextInitializer() {
return new SentryServletContextInitializer();
}
}