Package spark

Class 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.
    • 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 handler
      static boolean existsFor​(int status)
      Verifies that a custom error page exists for the given status code
      java.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()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
      • 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
    • Constructor Detail

      • CustomErrorPages

        private CustomErrorPages()
    • 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 -