Skip to main content
The SDK throws four error types. Always check for AbortError first (request cancellation), then NetworkError, then MaintenanceError, then the base HaspSDKError.

Error Types

DOMException (AbortError)

Thrown when a request is cancelled via AbortSignal or sdk.destroy(). This is not a network or server error.

NetworkError

Thrown when the fetch() call itself fails — device offline, DNS failure, etc. GET requests are retried automatically before this fires.

MaintenanceError

Thrown proactively when write operations are attempted while the SDK is in maintenance state.

HaspSDKError

The base class for all server-side errors. Check error.code against ErrorCode constants.

Complete Pattern

ErrorCode Constants

ErrorCode covers the codes an app typically branches on. Codes come from two places:
  • Set by the SDK itself: MISSING_APP_ID, UNAUTHORIZED, MAINTENANCE, NETWORK_ERROR, and UNKNOWN.
  • Passed through unchanged from the Data API’s error.code: every other code. The API can return codes with no constant (for example INTERNAL_ERROR or IP_NOT_ALLOWED); error.code is a plain string, so compare those directly.
The v1 SDK never removes a constant, so ErrorCode also still carries AccessDenied (ACCESS_DENIED), ReadOnlyRecord, StorageLimitReached, QueryTooComplex, and PreviewMode. They are deprecated and nothing returns them: getBootstrap() now refuses a user with no access with FORBIDDEN, like every other endpoint, so compare against ErrorCode.Forbidden.

Validation Field Errors

When error.code === ErrorCode.ValidationFailed, call error.getFieldErrors() to get a { fieldKey: 'message' } map of the first error per field:
For bulk operations, keys are prefixed with the item’s position in the batch — records.1.title, updates.0.id, ids.2 — so you can point at the exact row that failed.

401 Handling

On 401, the SDK calls onUnauthorized() (defaults to redirecting to the runtime sign-in page, /auth, and back to the current page afterwards) then throws HaspSDKError with ErrorCode.Unauthorized. Override onUnauthorized in the constructor to save draft state before redirecting.