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

Validation Field Errors

When error.code === ErrorCode.ValidationFailed, call error.getFieldErrors() to get a { fieldKey: 'message' } map of the first error per field:

401 Handling

On 401, the SDK calls onUnauthorized() (defaults to redirecting to /login) then throws HaspSDKError with ErrorCode.Unauthorized. Override onUnauthorized in the constructor to save draft state before redirecting.