MoEngageRequestFailure

@objc(MoEngageRequestFailure)
public class MoEngageRequestFailure : NSError, @unchecked Sendable

Failure delivered to MoEngageTaskProtocol.onFailure and thrown from MoEngageTaskProtocol.result(). Wraps a MoEngageRequestFailureReason, a human-readable message, and an optional underlying cause. NSError subclass for ObjC bridging.

Supports NSSecureCoding. On decode, the reason is reconstructed as the base MoEngageRequestFailureReason carrying the shared code — module-specific subclass metadata is dropped. When decoding chained failures, include both NSError.self and MoEngageRequestFailure.self in the unarchiver’s allow-list.

  • Error domain used by every MoEngageRequestFailure.

    Declaration

    Swift

    @objc
    public static let errorDomain: String
  • Reason describing the failure (shared code or module-specific subclass).

    Declaration

    Swift

    @objc
    public let reason: MoEngageRequestFailureReason
  • Human-readable failure message.

    Declaration

    Swift

    @objc
    public let message: String
  • Optional underlying cause (e.g. an NSError from the network layer).

    Declaration

    Swift

    @objc
    public let cause: NSError?
  • Create a failure wrapping a reason, message, and optional cause.

    Declaration

    Swift

    @objc
    public init(reason: MoEngageRequestFailureReason, message: String = "", cause: NSError? = nil)

    Parameters

    reason

    The reason describing the failure.

    message

    A human-readable failure message.

    cause

    Optional underlying NSError carrying additional context.

NSSecureCoding

  • Declaration

    Swift

    public override class var supportsSecureCoding: Bool { get }

Reason-subclass encoding limitation

  • Declaration

    Swift

    public required init?(coder: NSCoder)
  • Declaration

    Swift

    public override func encode(with coder: NSCoder)
  • Declaration

    Swift

    public override var description: String { get }

Common failure factories

  • Build the standard .sdkNotInitialized failure for the supplied workspace. nil workspaceId renders as <default> in the message.

    Declaration

    Swift

    static func sdkNotInitialized(workspaceId: String?) -> MoEngageRequestFailure
  • Build a .featureDisabled failure with a caller-provided message — lets callers differentiate analytics-disabled / opted-out / blacklisted without inventing module-specific codes.

    Declaration

    Swift

    static func featureDisabled(_ message: String) -> MoEngageRequestFailure
  • Returns a .featureDisabled rejection if data tracking is disabled or the user is opted out, otherwise nil. Centralises the two-toggle guard so typed-task public APIs surface a consistent failure when the SDK can do nothing.

    Declaration

    Swift

    static func dataTrackingDisabledFailure(
        forInstance sdkInstance: isolated MoEngageSDKInstance = #isolation
    ) -> MoEngageRequestFailure?