org.jooby.Router.err()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(115)

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

Router.err介绍

[英]Setup a route error handler. The error handler will be executed if current status code matches the one provided. All headers are reset while generating the error response.
[中]设置路由错误处理程序。如果当前状态代码与提供的代码匹配,将执行错误处理程序。生成错误响应时,会重置所有标题。

代码示例

代码示例来源:origin: jooby-project/jooby

/**
 * Setup a custom error handler.The error handler will be executed if the current exception is an
 * instance of given type type.
 *
 * All headers are reset while generating the error response.
 *
 * @param type Exception type. The error handler will be executed if the current exception is an
 *        instance of this type.
 * @param handler A route error handler.
 * @return This router.
 */
@Nonnull
default Router err(final Class<? extends Throwable> type, final Err.Handler handler) {
 return err((req, rsp, x) -> {
  if (type.isInstance(x) || type.isInstance(x.getCause())) {
   handler.handle(req, rsp, x);
  }
 });
}

代码示例来源:origin: jooby-project/jooby

/**
 * Setup a route error handler. The error handler will be executed if current status code matches
 * the one provided.
 *
 * All headers are reset while generating the error response.
 *
 * @param statusCode The status code to match.
 * @param handler A route error handler.
 * @return This router.
 */
@Nonnull
default Router err(final int statusCode, final Err.Handler handler) {
 return err((req, rsp, x) -> {
  if (statusCode == x.statusCode()) {
   handler.handle(req, rsp, x);
  }
 });
}

代码示例来源:origin: jooby-project/jooby

@Override
public void configure(final Env env, final Config conf, final Binder binder) {
 boolean whoops = conf.hasPath("whoops.enabled")
   ? conf.getBoolean("whoops.enabled")
   : "dev".equals(env.name());
 if (whoops) {
  ClassLoader loader = env.router().getClass().getClassLoader();
  Handler handler = prettyPage(loader, SourceLocator.local(), maxFrameSize, log);
  env.router().err(tryPage(handler, log));
 }
}

代码示例来源:origin: jooby-project/jooby

/**
 * Setup a route error handler. The error handler will be executed if current status code matches
 * the one provided.
 *
 * All headers are reset while generating the error response.
 *
 * @param predicate Apply the error handler if the predicate evaluates to <code>true</code>.
 * @param handler A route error handler.
 * @return This router.
 */
@Nonnull
default Router err(final Predicate<Status> predicate, final Err.Handler handler) {
 return err((req, rsp, err) -> {
  if (predicate.test(Status.valueOf(err.statusCode()))) {
   handler.handle(req, rsp, err);
  }
 });
}

代码示例来源:origin: jooby-project/jooby

/**
 * Setup a route error handler. The error handler will be executed if current status code matches
 * the one provided.
 *
 * All headers are reset while generating the error response.
 *
 * @param code The status code to match.
 * @param handler A route error handler.
 * @return This router.
 */
@Nonnull
default Router err(final Status code, final Err.Handler handler) {
 return err((req, rsp, x) -> {
  if (code.value() == x.statusCode()) {
   handler.handle(req, rsp, x);
  }
 });
}

代码示例来源:origin: org.jooby/jooby

/**
 * Setup a custom error handler.The error handler will be executed if the current exception is an
 * instance of given type type.
 *
 * All headers are reset while generating the error response.
 *
 * @param type Exception type. The error handler will be executed if the current exception is an
 *        instance of this type.
 * @param handler A route error handler.
 * @return This router.
 */
@Nonnull
default Router err(final Class<? extends Throwable> type, final Err.Handler handler) {
 return err((req, rsp, x) -> {
  if (type.isInstance(x) || type.isInstance(x.getCause())) {
   handler.handle(req, rsp, x);
  }
 });
}

代码示例来源:origin: org.jooby/jooby

/**
 * Setup a route error handler. The error handler will be executed if current status code matches
 * the one provided.
 *
 * All headers are reset while generating the error response.
 *
 * @param statusCode The status code to match.
 * @param handler A route error handler.
 * @return This router.
 */
@Nonnull
default Router err(final int statusCode, final Err.Handler handler) {
 return err((req, rsp, x) -> {
  if (statusCode == x.statusCode()) {
   handler.handle(req, rsp, x);
  }
 });
}

代码示例来源:origin: org.jooby/jooby-whoops

@Override
public void configure(final Env env, final Config conf, final Binder binder) {
 boolean whoops = conf.hasPath("whoops.enabled")
   ? conf.getBoolean("whoops.enabled")
   : "dev".equals(env.name());
 if (whoops) {
  ClassLoader loader = env.router().getClass().getClassLoader();
  Handler handler = prettyPage(loader, SourceLocator.local(), maxFrameSize, log);
  env.router().err(tryPage(handler, log));
 }
}

代码示例来源:origin: org.jooby/jooby

/**
 * Setup a route error handler. The error handler will be executed if current status code matches
 * the one provided.
 *
 * All headers are reset while generating the error response.
 *
 * @param predicate Apply the error handler if the predicate evaluates to <code>true</code>.
 * @param handler A route error handler.
 * @return This router.
 */
@Nonnull
default Router err(final Predicate<Status> predicate, final Err.Handler handler) {
 return err((req, rsp, err) -> {
  if (predicate.test(Status.valueOf(err.statusCode()))) {
   handler.handle(req, rsp, err);
  }
 });
}

代码示例来源:origin: org.jooby/jooby

/**
 * Setup a route error handler. The error handler will be executed if current status code matches
 * the one provided.
 *
 * All headers are reset while generating the error response.
 *
 * @param code The status code to match.
 * @param handler A route error handler.
 * @return This router.
 */
@Nonnull
default Router err(final Status code, final Err.Handler handler) {
 return err((req, rsp, x) -> {
  if (code.value() == x.statusCode()) {
   handler.handle(req, rsp, x);
  }
 });
}

相关文章

微信公众号

最新文章

更多