Package com.oorian
Class ErrorContext
java.lang.Object
com.oorian.ErrorContext
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:
-
Constructor Summary
ConstructorsConstructorDescriptionErrorContext(int statusCode, String requestPath, Throwable exception) Creates a new ErrorContext with the specified error details. -
Method Summary
Modifier and TypeMethodDescriptionstatic ErrorContextcurrent()Returns the current ErrorContext for the active request thread.Returns the exception that caused the error, if any.Returns the original request path that triggered the error.intReturns the HTTP status code for this error.
-
Constructor Details
-
ErrorContext
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 errorexception- the exception that caused the error, ornullif not applicable
-
-
Method Details
-
current
Returns the current ErrorContext for the active request thread.This method returns
nullwhen the current request is not being handled as an error page render.- Returns:
- the current ErrorContext, or
nullif 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
Returns the original request path that triggered the error.- Returns:
- the request path
-
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
nullif no exception is associated with this error
-