Errors and Retries

Handle Lumail SDK typed errors, rate limits, and retry behavior.

The SDK throws typed errors for HTTP failures so your application can branch on the error class instead of parsing raw responses.

import {
  LumailAuthenticationError,
  LumailNotFoundError,
  LumailRateLimitError,
  LumailValidationError,
} from "lumail";

try {
  await lumail.subscribers.get("[email protected]");
} catch (error) {
  if (error instanceof LumailNotFoundError) {
    console.log("Subscriber not found");
  } else if (error instanceof LumailRateLimitError) {
    console.log(`Retry after ${error.retryAfter}ms`);
  } else if (error instanceof LumailAuthenticationError) {
    console.log("Invalid API key");
  } else if (error instanceof LumailValidationError) {
    console.log(error.message);
  } else {
    throw error;
  }
}

Error Classes

ErrorMeaning
LumailValidationErrorRequest body or parameters are invalid
LumailAuthenticationErrorAPI token is missing or invalid
LumailPaymentRequiredErrorPlan limit or billing requirement blocks the request
LumailNotFoundErrorRequested resource does not exist
LumailRateLimitErrorRequest was rate limited
LumailErrorOther Lumail API error

Retry Behavior

MethodRetriesWhy
GET, PUT, DELETEUp to 3Safer to retry after network errors or rate limits
POST, PATCHNoneAvoids duplicate writes

Retry delays use exponential backoff: 1s, 2s, and 4s. Rate limit responses can include Retry-After; the SDK exposes it on LumailRateLimitError.retryAfter.

Idempotent Recovery Pattern

import { LumailNotFoundError } from "lumail";

export async function upsertSubscriber(
  email: string,
  fields: Record<string, string>,
) {
  try {
    return await lumail.subscribers.update(email, { fields });
  } catch (error) {
    if (error instanceof LumailNotFoundError) {
      return lumail.subscribers.create({ email, fields });
    }

    throw error;
  }
}