我正在尝试将https://rollbar.com/集成到Jhipster应用程序中。
在他们的documentation中,他们建议创建一个如下所示的类:
@ControllerAdvice
@EnableWebMvc
public class GlobalExceptionHandlerController {
public static final String DEFAULT_ERROR_VIEW = "error";
@ExceptionHandler(value = Exception.class)
public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
final Rollbar rollbar = new Rollbar(withAccessToken("8e194f5f31db4ff1b4e3e0951a40c936")
.environment("production").handleUncaughtErrors(true).build());
rollbar.error(e);
ModelAndView mav = new ModelAndView();
mav.addObject("exception", e);
mav.addObject("url", req.getRequestURL());
mav.setViewName(DEFAULT_ERROR_VIEW);
return mav;
}
但是,jHipster已经有一个用@ControllerAdvice
注释的类:public class ExceptionTranslator implements ProblemHandling
,如果我添加了上述方法,rollbar集成就可以了,但是随后
ExceptionTranslatorIntTest.testExceptionWithResponseStatus:126 Status expected:<400> but was:<200>
ExceptionTranslatorIntTest.testInternalServerError:135 Status expected:<500> but was:<200>
由于新方法禁止输入ExceptionTranslator.process(@Nullable ResponseEntity<Problem> entity)
方法。
我不确定要实现这两个功能的好方法是什么?
谢谢!