Class 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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      javax.ws.rs.WebApplicationException getError()
      Returns exception object only during rendering of configured error page (from ServerPagesAppBundle.AppBuilder.errorPage(int, String)).
      int getErrorCode()
      Shortcut for getError().getResponse().getStatus().
      java.lang.String getErroredUrl()
      Note returned only uri part (request.getRequestURI()).
      java.lang.String getErrorTrace()
      Method intended to be used in very simple error pages in order to quickly show stacktrace.
      • Methods inherited from class io.dropwizard.views.View

        getCharset, getTemplateName
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ErrorTemplateView

        public ErrorTemplateView()
      • ErrorTemplateView

        public ErrorTemplateView​(@Nullable
                                 java.lang.String templatePath)
      • ErrorTemplateView

        public ErrorTemplateView​(@Nullable
                                 java.lang.String templatePath,
                                 @Nullable
                                 java.nio.charset.Charset charset)
    • Method Detail

      • getError

        public javax.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:
        getError()
      • getErrorTrace

        public java.lang.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:
        getError()
      • getErroredUrl

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