Class ErrorPage
- Direct Known Subclasses:
DefaultErrorPage
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidcreateBody(Body body) Builds the error page body content using Oorian elements.protected final voidBuilds the complete HTML document by creating the head, body, and base stylesheet, then renders the element tree to an HTML string.protected voidcreateHead(Head head) Hook for subclasses to add additional elements to the<head>.protected static StringescapeHtml(String text) Escapes HTML special characters in the given text.Returns the exception that caused the error, if any.Returns the descriptive message for the current status code.protected StringgetMessage(int statusCode) Returns the descriptive message for the given HTTP status code.Returns the original request path that triggered the error.intReturns the HTTP status code for this error.getTitle()Returns the human-readable title for the current status code.protected StringgetTitle(int statusCode) Returns the human-readable title for the given HTTP status code.protected final booleanInitializes the error page by reading the error context and extracting the status code, request path, and exception.protected voidAppends the HTML doctype declaration and rendered page content to the given builder.Methods inherited from class com.oorian.HttpFile
addResponseHeader, create, getCacheControl, getDocumentUrl, getFullUrl, getHost, getHttpRequest, getOriginalParameters, getParameter, getParameterAsFloat, getParameterAsInt, getParameterAsLong, getParameterAsShort, getParameters, getParametersAFloat, getParametersAsInt, getParametersAsLong, getParametersAsShort, getParameterValues, getPath, getServletPath, getSessionId, getUrl, getUrlParameters, getWebResponse, hasParameter, hasUrlParams, isWritten, onCreated, onWriteComplete, setCacheControl, setCharacterEncoding, setContentType, setResponseHeader, setUrlParameters, toString, toString, write
-
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:
initializeFilein classHttpFile- Returns:
truealways, 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:
createFilein classHttpFile
-
toString
Appends the HTML doctype declaration and rendered page content to the given builder. -
createHead
Hook for subclasses to add additional elements to the<head>.Override this method to add custom
Styleelements, 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
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(), andgetMessage()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
Returns the original request path that triggered the error.- Returns:
- the request path, or
nullif not available
-
getException
Returns the exception that caused the error, if any.- Returns:
- the exception, or
nullif no exception is associated with this error
-
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
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
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
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
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
-