Skip to main content
The SDK uses a Result pattern. All methods return { data, error } instead of throwing exceptions.

Result pattern

Error types

The SDK produces two kinds of errors:
  1. Error instances for network failures, timeouts, aborted requests, and unexpected thrown values.
  2. ApiError instances for HTTP responses that return a non-2xx status.

ApiError

An ApiError is returned when the Layers API responds with an error status. It has the following fields:

ConfigError

A ConfigError is an Error subclass thrown during createSDK() when the SDK is misconfigured or used in an unsupported environment. The most common cause is missing fetch or localStorage in an environment where no custom implementation was provided.

Error handling with reactive state

Use subscribe to react to loading, errors, and data changes in any framework:

Retry behavior

The search controller automatically prepares queries and retries a 425 “not prepared yet” response. Most other controllers do not retry by default. To add retry logic, wrap the get() call in your own loop and use error.cause to inspect the original failure.

Common errors and fixes

For token and metafield issues, see the Troubleshooting section in Installation.

Next steps