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