AbortError first (request cancellation), then NetworkError, then MaintenanceError, then the base HaspSDKError.
Error Types
DOMException (AbortError)
Thrown when a request is cancelled viaAbortSignal or sdk.destroy(). This is not a network or server error.
NetworkError
Thrown when thefetch() 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. Checkerror.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, andUNKNOWN. - Passed through unchanged from the Data API’s
error.code: every other code. The API can return codes with no constant (for exampleINTERNAL_ERRORorIP_NOT_ALLOWED);error.codeis 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
Whenerror.code === ErrorCode.ValidationFailed, call error.getFieldErrors() to get a { fieldKey: 'message' } map of the first error per field:
records.1.title, updates.0.id, ids.2 — so you can point at the exact row that failed.
401 Handling
On 401, the SDK callsonUnauthorized() (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.