Result<T, OakError> instead of throwing exceptions. This gives you explicit control over success and failure paths at the type level.
The Result pattern
Result<T, E> is a discriminated union:
ok() and err() helpers if you need to create Result values in your own code:
Error types
All errors extendOakError. Check the error class to determine what went wrong.
| Error class | When it occurs | Key fields |
|---|---|---|
OakError | Base class for all SDK errors | message, cause |
SDKError | Internal SDK logic errors | message, cause |
ApiError | Non-2xx HTTP response from the API | status, body, headers |
NetworkError | Request failed to reach the server (DNS, timeout, connection refused) | isNetworkError: true |
AbortError | Request was cancelled via AbortSignal | message |
ParseError | Response body was not valid JSON | message, cause |
EnvironmentViolationError | A sandbox-only method was called in production | methodName, environment |
Handling API errors
ApiError is the most common error type. It contains the HTTP status code, the parsed response body, and response headers.
Retry configuration
The SDK includes built-in retry logic with exponential backoff. Configure it when creating the client.| Option | Type | Default | Description |
|---|---|---|---|
maxNumberOfRetries | number | 0 | Maximum number of retry attempts. Set to 0 to disable retries. |
delay | number | 500 | Initial delay in milliseconds before the first retry |
backoffFactor | number | 2 | Multiplier applied to the delay after each retry |
maxDelay | number | 30000 | Maximum delay cap in milliseconds |
retryOnStatus | number[] | [408, 429, 500, 502, 503, 504] | HTTP status codes that trigger a retry |
retryOnError | (error) => boolean | Network errors only | Custom function to decide if an error is retryable |
onRetry | (attempt, error) => void | undefined | Callback fired before each retry attempt. The SDK does not log retries by default — pass your own logger here. |
signal | AbortSignal | — | Signal to cancel retries |
Retry-After header when the API returns 429 Too Many Requests.
Sandbox-only methods
Some operations are restricted to the sandbox environment. If you call a sandbox-only method in production, the SDK returns anEnvironmentViolationError without making a network request.
For more on environment behavior, see Environments.