Errors

The SDK error surface — one error model, expressed in each platform's native idiom

Every SDK surfaces the same error model, mirroring the API error object: authentication failures, invalid referral codes, invalid requests, rate limits, and network failures. Two behaviors hold everywhere:

SituationBehavior
Bad publishable keyAuthentication error on the first network call.
Invalid/expired code passed to applyCodeInvalid-request error with code invalid_referral_code.
Rate limitedRate-limit error; batched track calls back off and retry automatically.
Network failure during trackEvents are retained and retried with the same idempotency key — no data loss, no duplicates.

track never throws on any platform — events are retained offline and retried with the same idempotency key.

Every rejected promise throws InvitebaseError:

class InvitebaseError extends Error {
  type: 'invalid_request_error' | 'authentication_error' | 'rate_limit_error' | 'api_error';
  code?: string;    // machine-readable, e.g. 'invalid_referral_code'
  param?: string;   // the offending parameter, when applicable
  message: string;
}
import invitebase, { InvitebaseError } from '@invitebase/js';

try {
  await invitebase.getReferralLink('7e1f8a3b-4c26-49d0-b591-0d8e2f6a3c15');
} catch (err) {
  if (err instanceof InvitebaseError && err.type === 'authentication_error') {
    console.error('Check NEXT_PUBLIC_INVITEBASE_PUBLISHABLE_KEY');
  } else {
    throw err;
  }
}