Class ErrorTemplateView

java.lang.Object
io.dropwizard.views.common.View
ru.vyarus.guicey.gsp.views.template.TemplateView
ru.vyarus.guicey.gsp.views.template.ErrorTemplateView

public class ErrorTemplateView extends TemplateView
Error template rendering model. Must be used for error pages (registered in main bundle ServerPagesAppBundle.AppBuilder.errorPage(int, String)). Provides access to original error and original (failed) page url (note that it can't be taken from current context request because error page is rendered as usual page and so current request will contain error page url only).

There are 3 possible exception cases:

  • AssetError for static asset serving error
  • TemplateRestCodeError for error code directly returned from rest without throwing exception (e.g. Response.status(404).build())
  • Any exception extending WebApplicationException. This is exactly exception thrown in rest method or simple exception wrapped with WebApplicationException.
Note that not "real" exception types implement TracelessException to simplify detection of exception with meaningful trace.

Note: in contrast to usual templates, during error page rendering context request will contain error page path, but original url is still available with getErroredUrl().

Since:
31.01.2019
  • Constructor Details

    • ErrorTemplateView

      public ErrorTemplateView()
    • ErrorTemplateView

      public ErrorTemplateView(@Nullable String templatePath)
    • ErrorTemplateView

      public ErrorTemplateView(@Nullable String templatePath, @Nullable Charset charset)
  • Method Details

    • getError

      public jakarta.ws.rs.WebApplicationException getError()
      Returns exception object only during rendering of configured error page (from ServerPagesAppBundle.AppBuilder.errorPage(int, String)). For all other cases (from error pages) method is useless.
      Returns:
      exception object or null (for normal template rendering)
    • getErrorCode

      public int getErrorCode()
      Shortcut for getError().getResponse().getStatus(). Shortcut created because direct expression can't be used in freemarker expression.
      Returns:
      status code from context error or -1 if no context error
      See Also:
    • getErrorTrace

      public String getErrorTrace()
      Method intended to be used in very simple error pages in order to quickly show stacktrace.

      Note that in case of direct error code return (404, 500 etc) exception will be "empty" (exception instance will be created but not thrown).

      Returns:
      current stacktrace as string or null if no context error
      See Also:
    • getErroredUrl

      public String getErroredUrl()
      Note returned only uri part (request.getRequestURI()).
      Returns:
      page url cause redirect to error page