@Test public void testSetExceptionHandler() throws Exception { String path = "/blah"; router.route(path).handler(rc -> { throw new RuntimeException("ouch!"); }); CountDownLatch latch = new CountDownLatch(1); router.exceptionHandler(t -> { assertEquals("ouch!", t.getMessage()); latch.countDown(); }); testRequest(HttpMethod.GET, path, 500, "Internal Server Error"); awaitLatch(latch); }
@Override public Router exceptionHandler(Handler<Throwable> exceptionHandler) { return router.exceptionHandler(exceptionHandler); }
@Override public Router exceptionHandler(Handler<Throwable> exceptionHandler) { return delegate.exceptionHandler(exceptionHandler); }
/** * Specify a handler for any unhandled exceptions on this router. The handler will be called for exceptions thrown * from handlers. This does not affect the normal failure routing logic. * @param exceptionHandler the exception handler * @return a reference to this, so the API can be used fluently */ @Deprecated() public io.vertx.rxjava.ext.web.Router exceptionHandler(Handler<Throwable> exceptionHandler) { delegate.exceptionHandler(exceptionHandler); return this; }
/** * Specify a handler for any unhandled exceptions on this router. The handler will be called for exceptions thrown * from handlers. This does not affect the normal failure routing logic. * @param exceptionHandler the exception handler * @return a reference to this, so the API can be used fluently */ @Deprecated() public io.vertx.rxjava.ext.web.Router exceptionHandler(Handler<Throwable> exceptionHandler) { delegate.exceptionHandler(exceptionHandler); return this; }
@Test public void testTemplateEngineFail() throws Exception { TemplateEngine engine = new TestEngine(true); router.route().handler(TemplateHandler.create(engine, "somedir", "text/html")); router.exceptionHandler(t -> { assertEquals("eek", t.getMessage()); testComplete(); }); testRequest(HttpMethod.GET, "/foo.html", 500, "Internal Server Error"); await(); }
public void init() { LOG.info("Starting Vert.x Dispatcher at [{}:{}]", host, port); httpServer = vertx.createHttpServer(); router = Router.router(vertx); router.exceptionHandler(e -> LOG.error(e.getMessage(), e)); router.route().order(0).handler(bodyHandler.setBodyLimit(maxUploadSize)); router.route().last().handler(f -> { if (!f.response().ended() && f.response().bytesWritten() == 0) { f.response().end(ErrorMessages.buildJson(ErrorMessages.NOT_FOUND)); } }); CountDownLatch await = new CountDownLatch(1); httpServer.requestHandler(router::accept).listen(port, host, r -> await.countDown()); try { if (!await.await(30, TimeUnit.SECONDS)) { throw new RuntimeException("Failed to start Vert.x server!"); } } catch (Throwable t) { throw Exceptions.runtime(t); } isOpen = true; }
@Test public void testSetExceptionHandler() throws Exception { String path = "/blah"; router.route(path).handler(rc -> { throw new RuntimeException("ouch!"); }); CountDownLatch latch = new CountDownLatch(1); router.exceptionHandler(t -> { assertEquals("ouch!", t.getMessage()); latch.countDown(); }); testRequest(HttpMethod.GET, path, 500, "Internal Server Error"); awaitLatch(latch); }
@Test public void testTemplateEngineFail() throws Exception { TemplateEngine engine = new TestEngine(true); router.route().handler(TemplateHandler.create(engine, "somedir", "text/html")); router.exceptionHandler(t -> { assertEquals("eek", t.getMessage()); testComplete(); }); testRequest(HttpMethod.GET, "/foo.html", 500, "Internal Server Error"); await(); }
.exceptionHandler(error -> log.error(error.getMessage(), error));
}); router.exceptionHandler(event -> { logger.error(event.getMessage(), event.getCause()); });