Package com.oorian

Class ErrorPage

Direct Known Subclasses:
DefaultErrorPage

public abstract class ErrorPage extends HttpFile
Abstract base class for building custom error pages using Oorian's element-based API.

ErrorPage extends HttpFile and provides a bare HTML document skeleton with a minimal CSS reset. Subclasses implement createBody(Body) to build the error page using standard Oorian elements (H1, Paragraph, Div, etc.) instead of raw StringBuilder HTML.

Error details are read from ErrorContext.current() during initialization and exposed through convenience getters: getStatusCode(), getRequestPath(), and getException().

Usage:


 public class MyErrorPage extends ErrorPage
 {
     @Override
     protected void createBody(Body body)
     {
         body.addElement(new H1("Error " + getStatusCode()));
         body.addElement(new Paragraph(getMessage()));
         body.addElement(new Paragraph("Path: " + getRequestPath()));
     }
 }

 // Register in Application.initialize()
 setErrorPage(404, MyErrorPage.class);
 setDefaultErrorPage(MyErrorPage.class);
 

Unlike HtmlPage, ErrorPage does not start a WebSocket or event system. Error pages are lightweight, standalone HTML pages that render reliably even when the normal page infrastructure has failed.

Since:
2.1
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • ErrorPage

      public ErrorPage()
      Creates a new ErrorPage instance.
  • Method Details

    • initializeFile

      protected final boolean initializeFile()
      Initializes the error page by reading the error context and extracting the status code, request path, and exception.
      Overrides:
      initializeFile in class HttpFile
      Returns:
      true always, indicating the page should be rendered
    • createFile

      protected final void createFile()
      Builds the complete HTML document by creating the head, body, and base stylesheet, then renders the element tree to an HTML string.
      Specified by:
      createFile in class HttpFile
    • toString

      protected void toString(StringBuilder sb)
      Appends the HTML doctype declaration and rendered page content to the given builder.
      Specified by:
      toString in class HttpFile
      Parameters:
      sb - the StringBuilder to append the HTML output to
    • createHead

      protected void createHead(Head head)
      Hook for subclasses to add additional elements to the <head>.

      Override this method to add custom Style elements, meta tags, or other head content. The base implementation does nothing. The head already contains charset, viewport, title, and base CSS reset styles when this method is called.

      Parameters:
      head - the Head element to add content to
    • createBody

      protected abstract void createBody(Body body)
      Builds the error page body content using Oorian elements.

      Subclasses implement this method to populate the body with elements such as H1, Paragraph, Div, etc.

      Use the convenience getters getStatusCode(), getRequestPath(), getException(), getTitle(), and getMessage() to access error details.

      Parameters:
      body - the Body element to add content to
    • getStatusCode

      public int getStatusCode()
      Returns the HTTP status code for this error.
      Returns:
      the status code (e.g., 400, 404, 500)
    • getRequestPath

      public String getRequestPath()
      Returns the original request path that triggered the error.
      Returns:
      the request path, or null if not available
    • getException

      public Throwable getException()
      Returns the exception that caused the error, if any.
      Returns:
      the exception, or null if no exception is associated with this error
    • getTitle

      public String getTitle()
      Returns the human-readable title for the current status code.

      Delegates to getTitle(int) with this page's status code.

      Returns:
      the error page title
    • getMessage

      public String getMessage()
      Returns the descriptive message for the current status code.

      Delegates to getMessage(int) with this page's status code.

      Returns:
      the error page message
    • getTitle

      protected String getTitle(int statusCode)
      Returns the human-readable title for the given HTTP status code.

      Subclasses may override this method to provide custom titles.

      Parameters:
      statusCode - the HTTP status code
      Returns:
      the error page title
    • getMessage

      protected String getMessage(int statusCode)
      Returns the descriptive message for the given HTTP status code.

      Subclasses may override this method to provide custom messages.

      Parameters:
      statusCode - the HTTP status code
      Returns:
      the error page message
    • escapeHtml

      protected static String escapeHtml(String text)
      Escapes HTML special characters in the given text.
      Parameters:
      text - the text to escape
      Returns:
      the escaped text, or an empty string if text is null