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 returned during createSDK() when the SDK is misconfigured or used in an unsupported environment. A storage-related error occurs only when you pass a storage value in an environment without localStorage; the SDK does not access localStorage on its own. ConfigError is not exported, so match on error.name === 'ConfigError' or handle error directly.

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