Skip to main content

Error Handling & Retry

Cruxstack Node SDK provides clear errors and automatic retry with queueing for resilient tracking.

Error Handling

  • Initialization required: Throws if you call SDK functions before init().
  • Validation errors: Config, events, and traits parameters are validated (Zod). Invalid data throws descriptive errors.
  • Network/API errors: Failed event sends are queued for retry.

Automatic Retry & Queue

  • Immediate send: Events are sent as soon as you call cruxTrack.
  • Queue on failure: If sending fails (e.g., network error), the event is added to a retry queue.
  • Automatic retry: Queued events are retried every 10 seconds, up to 3 times.
  • Max retries: After 3 failed attempts, the event is dropped and an error is logged.

Utility Functions

  • getQueueSize(): Returns the number of events in the retry queue.
  • clearQueue(): Clears all queued events.

Example Error Messages

  • "SDK not initialized. Call init() first."
  • "Category name is required and must be a non-empty string"
  • "SDK initialization failed: [reason]"
  • "Event tracking failed: [reason]"
  • "Failed to send event: [reason]"
  • "userIds is required"
  • "At least one userId is required"
  • "All userIds must be non-empty strings"
  • "customerId is required for getUserTraits"