Package spark
Class CustomErrorPages
- java.lang.Object
-
- spark.CustomErrorPages
-
public class CustomErrorPages extends java.lang.Object
Holds the custom error pages. A page can be defined as a String or a Route. Note that this class is always used statically therefore custom error pages will be shared between different instances of the Service class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
CustomErrorPages.SingletonHolder
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMap<java.lang.Integer,java.lang.Object>
customPages
private java.util.HashMap<java.lang.Integer,java.lang.String>
defaultPages
static java.lang.String
INTERNAL_ERROR
private static org.slf4j.Logger
LOG
static java.lang.String
NOT_FOUND
-
Constructor Summary
Constructors Modifier Constructor Description private
CustomErrorPages()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static void
add(int status, java.lang.String page)
Add a custom error page as a String(package private) static void
add(int status, Route route)
Add a custom error page as a Route handlerstatic boolean
existsFor(int status)
Verifies that a custom error page exists for the given status codejava.lang.String
getDefaultFor(int status)
Returns the default error page for a given status code.static java.lang.Object
getFor(int status, Request request, Response response)
Gets the custom error page for a given status code.private static CustomErrorPages
getInstance()
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
NOT_FOUND
public static final java.lang.String NOT_FOUND
- See Also:
- Constant Field Values
-
INTERNAL_ERROR
public static final java.lang.String INTERNAL_ERROR
- See Also:
- Constant Field Values
-
customPages
private final java.util.HashMap<java.lang.Integer,java.lang.Object> customPages
-
defaultPages
private final java.util.HashMap<java.lang.Integer,java.lang.String> defaultPages
-
-
Method Detail
-
existsFor
public static boolean existsFor(int status)
Verifies that a custom error page exists for the given status code- Parameters:
status
-- Returns:
- true if error page exists
-
getFor
public static java.lang.Object getFor(int status, Request request, Response response)
Gets the custom error page for a given status code. If the custom error page is a route, the output of its handle method is returned. If the custom error page is a String, it is returned as an Object.- Parameters:
status
-request
-response
-- Returns:
- Object representing the custom error page
-
getDefaultFor
public java.lang.String getDefaultFor(int status)
Returns the default error page for a given status code. Guaranteed to never be null.- Parameters:
status
-- Returns:
- String representation of the default error page.
-
add
static void add(int status, java.lang.String page)
Add a custom error page as a String- Parameters:
status
-page
-
-
add
static void add(int status, Route route)
Add a custom error page as a Route handler- Parameters:
status
-route
-
-
getInstance
private static CustomErrorPages getInstance()
-
-