0

I'm trying to set a custom ErrorHandler in dropwizard 1.0.2

In my Application class in the run method I have the following lines:

  environment.getApplicationContext().setErrorHandler(new CustomErrorHandler());
  environment.getAdminContext().setErrorHandler(new CustomErrorHandler());

However, the code from CustomErrorHandler is not called, instead default ErrorHandler class is being used when e.g. I hit a URL that cannot be served.

While debugging the issue, I realize that ContainerLifeCycle object contains the following bean: {org.eclipse.jetty.server.handler.ErrorHandler@375084c9,AUTO} and does not contain a bean for CustomErrorHandler. My guess is that my error handler gets overwritten when default ErroHandler is set later upon application startup.

Any pointers how to set a custom error handler would be highly appreciated.

Vyacheslav
  • 1,186
  • 2
  • 15
  • 29

1 Answers1

1

The only way I've managed to do this is within a server lifecycle listener, e.g.

environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() {
        @Override
        public void serverStarted(Server server) {
            server.setErrorHandler(new MyCustomErrorHandler());
        }
    });
hbakkum
  • 73
  • 2
  • 6