Package spark

Class CustomErrorPages

java.lang.Object
spark.CustomErrorPages

public class CustomErrorPages extends 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 Details

  • Constructor Details

    • CustomErrorPages

      private CustomErrorPages()
  • Method Details

    • 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 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 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, 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()