Class PushError

java.lang.Object
java.lang.Throwable
java.lang.Exception
com.iizix.server.push.engine.http.PushError
All Implemented Interfaces:
Serializable

public final class PushError extends Exception
A refused request: the HTTP status, the error code from the closed vocabulary of PushWire.ERRORS and the human message, plus any extra members the reply carries (a 409 carries vapid_reason and fcm_reason).

Every failure the handler answers is one of these, so the reply shape of PUSH-WIRE-CONTRACT.md section 1.2 is built in one place, toJSON().

Author:
Christopher Mindus
See Also:
  • Field Details

    • status

      public final int status
      The HTTP status.
    • code

      public final String code
      The error code, one of PushWire.ERRORS.
  • Constructor Details

    • PushError

      public PushError(int status, String code, String message)
      Constructor.
      Parameters:
      status - The HTTP status.
      code - The error code, one of PushWire.ERRORS.
      message - The human text, English, never localised, never a stack trace.
    • PushError

      public PushError(int status, String code, String message, JSONObject extra)
      Constructor with extra reply members.
      Parameters:
      status - The HTTP status.
      code - The error code, one of PushWire.ERRORS.
      message - The human text.
      extra - Extra members of the reply, null for none.
  • Method Details

    • badRequest

      public static PushError badRequest(String message)
      A 400 bad_request.
      Parameters:
      message - The human text.
      Returns:
      The error.
    • unauthenticated

      public static PushError unauthenticated(String message)
      A 401 unauthenticated.
      Parameters:
      message - The human text.
      Returns:
      The error.
    • forbidden

      public static PushError forbidden(String message)
      A 403 forbidden.
      Parameters:
      message - The human text.
      Returns:
      The error.
    • toJSON

      public JSONObject toJSON()
      Builds the reply body: {ok:false, error, message} plus the extra members.
      Returns:
      A new JSON object.