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

Result Pattern

const result = await collection.execute()

if (result.error) {
  switch (result.error._tag) {
    case 'NetworkError':
      // Connection issues, timeouts, aborted requests
      break
    case 'ApiError':
      // Server errors, rate limits
      break
    case 'ValidationError':
      // Invalid parameters
      break
    case 'ConfigError':
      // SDK configuration issues
      break
  }
} else {
  const data = result.data
}

Error Types

All errors have a _tag property for type discrimination:
Error TagDescriptionRetryable
NetworkErrorConnection issues, timeouts, aborted requestsUsually
ApiErrorServer errors, rate limits5xx, 429
ValidationErrorInvalid input parametersNo
ConfigErrorSDK misconfigurationNo

Error Handling in Components

When using reactive methods with Preact components, handle errors in your render logic:
function ProductList() {
  const { data, error, fetching } = collection.state.value

  if (fetching) {
    return <LoadingSpinner />
  }

  if (error) {
    return <ErrorMessage message="Something went wrong. Please try again." />
  }

  if (!data || data.products.length === 0) {
    return <EmptyState message="No products found." />
  }

  return (
    <div className="product-grid">
      {data.products.map(product => (
        <ProductCard key={product.id} product={product} />
      ))}
    </div>
  )
}