1

I'm trying to integrate https://rollbar.com/ into a Jhipster Application.

In their documentation, they suggest to create a class like the following:

@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;
    }

However, jHipster already has a class annotated with @ControllerAdvice: public class ExceptionTranslator implements ProblemHandling, and if I add the above method, the rollbar integration works, but then I get failed tests for

ExceptionTranslatorIntTest.testExceptionWithResponseStatus:126 Status expected:<400> but was:<200>
  ExceptionTranslatorIntTest.testInternalServerError:135 Status expected:<500> but was:<200>

Since the new method prevents entering the ExceptionTranslator.process(@Nullable ResponseEntity<Problem> entity) method.

I'm not sure what is a good approach to achieve both functionalities?

Thank You!

4

0 回答 0