io.vertx.ext.web.Router.exceptionHandler()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(152)

本文整理了Java中io.vertx.ext.web.Router.exceptionHandler方法的一些代码示例,展示了Router.exceptionHandler的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Router.exceptionHandler方法的具体详情如下:
包路径:io.vertx.ext.web.Router
类名称:Router
方法名:exceptionHandler

Router.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.
[中]为此路由器上任何未处理的异常指定处理程序。对于处理程序引发的异常,将调用该处理程序。这不会影响正常的故障路由逻辑。

代码示例

代码示例来源:origin: vert-x3/vertx-web

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

代码示例来源:origin: org.zalando/vertx-swagger

@Override
public Router exceptionHandler(Handler<Throwable> exceptionHandler) {
  return router.exceptionHandler(exceptionHandler);
}

代码示例来源:origin: wang007/vertx-start

@Override
public Router exceptionHandler(Handler<Throwable> exceptionHandler) {
  return delegate.exceptionHandler(exceptionHandler);
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * 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;
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * 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;
}

代码示例来源:origin: vert-x3/vertx-web

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

代码示例来源:origin: dmart28/gcplot

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

代码示例来源:origin: io.vertx/vertx-web

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

代码示例来源:origin: io.vertx/vertx-web

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

代码示例来源:origin: apiman/apiman

.exceptionHandler(error -> log.error(error.getMessage(), error));

代码示例来源:origin: GruppoFilippetti/vertx-mqtt-broker

});
router.exceptionHandler(event -> {
  logger.error(event.getMessage(), event.getCause());
});

相关文章