Maxim Popov
Maxim Popov

Reputation: 1227

How to Configure Global Error Handling in Jetty Server for Pre-Servlet Errors

I'm trying to configure my Jetty 12 server to forward requests to an "/error" page for all error scenarios, including those occurring before servlet initialization (e.g., during early request processing).

I've successfully configured error handling for ServletContextHandler/WebAppContext using ErrorHandler, but I'm unclear how to handle errors that occur earlier in the request lifecycle.

Current Approach:

I believe I need to set a global error handler via Server.setErrorHandler(), potentially using either: Jetty's ByHttpStatus error handler or a custom ReHandlingErrorHandler.

Key Question:

What should be passed as the handler parameter to ReHandlingErrorHandler constructor? The Jetty test suite uses the Server object itself, but is this production-safe? Could this cause infinite recursion if the error handling process itself fails?

ReHandlingErrorHandler errorHandler = new ReHandlingErrorHandler(/* what goes here? */);
server.setErrorHandler(errorHandler);

Upvotes: 0

Views: 17

Answers (0)

Related Questions