Error Handling

The SDK throws typed errors you can catch individually for proper error handling.

Error classes

Error ClassHTTP StatusWhen
LysticaAuthError401Missing or invalid API key
LysticaForbiddenError403Insufficient scope or IP block
LysticaNotFoundError404Resource does not exist
LysticaValidationError422Invalid request data
LysticaRateLimitError429Rate limit exceeded
LysticaErroranyAll other API errors
LysticaNetworkErrorNetwork failure or timeout

Example

import {
  LysticaCloud,
  LysticaAuthError,
  LysticaForbiddenError,
  LysticaNotFoundError,
  LysticaValidationError,
  LysticaRateLimitError,
  LysticaError,
  LysticaNetworkError,
} from "lystica-cloud";

try {
  const { data } = await lystica.contacts.list();
} catch (err) {
  if (err instanceof LysticaAuthError) {
    console.error("Invalid or expired API key");
  } else if (err instanceof LysticaForbiddenError) {
    console.error("Insufficient permissions");
  } else if (err instanceof LysticaNotFoundError) {
    console.error("Resource not found");
  } else if (err instanceof LysticaValidationError) {
    console.error("Invalid request data:", err.message);
  } else if (err instanceof LysticaRateLimitError) {
    console.error("Rate limit exceeded — slow down");
  } else if (err instanceof LysticaNetworkError) {
    console.error("Network failure:", err.message);
  } else if (err instanceof LysticaError) {
    console.error(`API error ${err.status}: ${err.message}`);
  } else {
    throw err;
  }
}

We use cookies

We use cookies to enhance your experience, analyze site usage, and assist in our marketing efforts. You can manage your preferences or learn more in our Cookie Policy.