private static HttpHandler exceptionHandler(HttpHandler next) { return Handlers.exceptionHandler(next) .addExceptionHandler(Throwable.class, ExceptionHandlers::handleAllExceptions); }
public static ExceptionHandler exception(HttpHandler handler) { return Handlers.exceptionHandler((HttpServerExchange exchange) -> { try { handler.handleRequest(exchange); } catch (Throwable th) { log.error("exception thrown at " + exchange.getRequestURI(), th); throw th; } }); }
public void startServer() { if (!this.error) { this.host = this.config.getString(Key.APPLICATION_HOST, Default.APPLICATION_HOST.toString()); this.port = this.config.getInt(Key.APPLICATION_PORT, Default.APPLICATION_PORT.toInt()); Undertow server = Undertow.builder() .addHttpListener(this.port, this.host) .setHandler(Handlers.exceptionHandler(this.pathHandler).addExceptionHandler(Throwable.class, new ExceptionHandler())) .build(); server.start(); this.undertow = server; } }