{ 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 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
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.