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.
    • retryAfter

      public final long retryAfter
      The seconds of the Retry-After header the reply carries, zero for none: only tooManyAttempts(long) sets it.
  • 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 localized, 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.
    • tooManyAttempts

      public static PushError tooManyAttempts(long retryAfterSeconds)
      A 429 for a request whose source is held back after too many failed attempts: the per-source throttle of the server's sign-in (order 638, CC-FIX-PUSH-API-SIGNIN). The error is unauthenticated - the caller is not authenticated, and the closed vocabulary of PushWire.ERRORS is not widened - and the reply carries Retry-After. It tells the caller nothing about any account: the same answer whatever the user name and the password.
      Parameters:
      retryAfterSeconds - The seconds until the source may attempt again; at least 1 is sent.
      Returns:
      The error.
    • toJSON

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