Skip to main content
The SDK uses a Result pattern for error handling. All methods return Result<T, E> rather than throwing exceptions.

Result pattern

Error types

All errors have a _tag property for type discrimination.

NetworkError

Connection failures, timeouts, and aborted requests.

ApiError

Server errors, rate limits, and GraphQL errors. Some ApiErrors report config drift rather than a transient failure. A 401 usually means the storefront token is missing or invalid. Messages like "The selected sort order code is invalid." and "The selected facets.N is invalid." mean a registered sorts[].code or facets[].code no longer exists in the Layers dashboard. See Troubleshooting for fixes.

ValidationError

Invalid parameters passed to SDK methods.

ConfigError

SDK configuration issues at init time.

Error helpers

The SDK provides utility functions for handling retryable errors:

Error handling with reactive state

Handle errors reactively using the controller’s subscribe method. This approach works with any framework:
For framework-specific patterns, see Framework Integration.