{ data, error } instead of throwing exceptions.
Result pattern
Error types
The SDK produces two kinds of errors:Errorinstances for network failures, timeouts, aborted requests, and unexpected thrown values.ApiErrorinstances for HTTP responses that return a non-2xx status.
ApiError
AnApiError is returned when the Layers API responds with an error status. It has the following fields:
ConfigError
AConfigError 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
Usesubscribe to react to loading, errors, and data changes in any framework:
Retry behavior
Thesearch 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.