PushX.Response (PushX v0.5.0)

Copy Markdown View Source

A struct representing the response from a push notification request.

Fields

  • :provider - The provider used (:apns or :fcm)
  • :status - The result status (see below)
  • :id - Provider-specific message ID (if available)
  • :reason - Error reason string (if failed)
  • :raw - Raw response body (for debugging)

Status Values

  • :sent - Message was successfully sent
  • :invalid_token - Device token is invalid or expired
  • :expired_token - Device token has expired
  • :unregistered - Device is no longer registered
  • :payload_too_large - Payload exceeds size limit
  • :rate_limited - Too many requests, try again later
  • :server_error - Provider server error
  • :connection_error - Network/connection failure
  • :unknown_error - Unrecognized error

Summary

Functions

Maps an APNS error reason to a status atom.

Creates an error response.

Creates an error response with raw data.

Creates an error response with raw data and retry_after value.

Maps an FCM error code to a status atom.

Returns true if the error is retryable.

Returns true if the token should be removed from the database.

Creates a successful response.

Returns true if the response indicates success.

Types

status()

@type status() ::
  :sent
  | :invalid_token
  | :expired_token
  | :unregistered
  | :payload_too_large
  | :rate_limited
  | :server_error
  | :connection_error
  | :unknown_error

t()

@type t() :: %PushX.Response{
  id: String.t() | nil,
  provider: :apns | :fcm,
  raw: any(),
  reason: String.t() | nil,
  retry_after: non_neg_integer() | nil,
  status: status()
}

Functions

apns_reason_to_status(reason)

@spec apns_reason_to_status(String.t()) :: status()

Maps an APNS error reason to a status atom.

See: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/handling_notification_responses_from_apns

error(provider, status, reason \\ nil)

@spec error(provider :: :apns | :fcm, status :: status(), reason :: String.t() | nil) ::
  t()

Creates an error response.

error(provider, status, reason, raw)

@spec error(
  provider :: :apns | :fcm,
  status :: status(),
  reason :: String.t() | nil,
  raw :: any()
) :: t()

Creates an error response with raw data.

error(provider, status, reason, raw, retry_after)

@spec error(
  provider :: :apns | :fcm,
  status :: status(),
  reason :: String.t() | nil,
  raw :: any(),
  retry_after :: non_neg_integer() | nil
) :: t()

Creates an error response with raw data and retry_after value.

fcm_error_to_status(error_code)

@spec fcm_error_to_status(String.t()) :: status()

Maps an FCM error code to a status atom.

See: https://firebase.google.com/docs/reference/fcm/rest/v1/ErrorCode

retryable?(response)

@spec retryable?(t()) :: boolean()

Returns true if the error is retryable.

Retryable errors:

  • :connection_error - Network/connection failure
  • :rate_limited - Too many requests (with backoff)
  • :server_error - Provider server error (5xx)

should_remove_token?(response)

@spec should_remove_token?(t()) :: boolean()

Returns true if the token should be removed from the database.

success(provider, id \\ nil)

@spec success(provider :: :apns | :fcm, id :: String.t() | nil) :: t()

Creates a successful response.

success?(response)

@spec success?(t()) :: boolean()

Returns true if the response indicates success.