Package com.oorian

Class ErrorContext

java.lang.Object
com.oorian.ErrorContext

public class ErrorContext extends Object
Holds error information for the current request when rendering an error page.

When the Oorian framework encounters an error (such as a page not found, authentication failure, or unhandled exception), it creates an ErrorContext and makes it available to the error page via a thread-local. Error pages can retrieve the context to display appropriate error information.

Usage in an error page:


 @Page("/error")
 public class MyErrorPage extends HtmlPage {
     @Override
     protected void createBody(Body body) {
         ErrorContext ctx = ErrorContext.current();
         if (ctx != null) {
             body.addElement(new H1("Error " + ctx.getStatusCode()));
             body.addElement(new Paragraph(ctx.getRequestPath()));
         }
     }
 }
 
Since:
2.1
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • ErrorPageRegistry
  • Constructor Details

    • ErrorContext

      public ErrorContext(int statusCode, String requestPath, Throwable exception)
      Creates a new ErrorContext with the specified error details.
      Parameters:
      statusCode - the HTTP status code (e.g., 404, 500)
      requestPath - the original request path that triggered the error
      exception - the exception that caused the error, or null if not applicable
  • Method Details

    • current

      public static ErrorContext current()
      Returns the current ErrorContext for the active request thread.

      This method returns null when the current request is not being handled as an error page render.

      Returns:
      the current ErrorContext, or null if no error context is active
    • getStatusCode

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

      public String getRequestPath()
      Returns the original request path that triggered the error.
      Returns:
      the request path
    • getException

      public Throwable getException()
      Returns the exception that caused the error, if any.

      This is typically set for 500 Internal Server Error responses where an unhandled exception occurred during page rendering.

      Returns:
      the exception, or null if no exception is associated with this error