Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.usehasp.com/llms.txt

Use this file to discover all available pages before exploring further.

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.
if (error instanceof DOMException && error.name === 'AbortError') {
  return; // cancelled — no action needed
}

NetworkError

Thrown when the fetch() call itself fails — device offline, DNS failure, etc. GET requests are retried automatically before this fires.
if (error instanceof HaspSDK.NetworkError) {
  showMessage('Check your internet connection.');
}

MaintenanceError

Thrown proactively when write operations are attempted while the SDK is in maintenance state.
if (error instanceof HaspSDK.MaintenanceError) {
  showMessage('App is being updated. Try again shortly.');
}

HaspSDKError

The base class for all server-side errors. Check error.code against ErrorCode constants.
if (error instanceof HaspSDK.HaspSDKError) {
  const { ErrorCode } = HaspSDK;

  if (error.code === ErrorCode.ValidationFailed) {
    const fieldErrors = error.getFieldErrors();
    showFieldErrors(fieldErrors);
  } else if (error.code === ErrorCode.NotFound) {
    showMessage('Record not found.');
  } else if (error.code === ErrorCode.AccessDenied) {
    showMessage('You do not have permission.');
  } else if (error.code === ErrorCode.RateLimited) {
    showMessage('Too many requests. Try again shortly.');
  } else {
    showMessage('Something went wrong. Please try again.');
  }
}

Complete Pattern

const { ErrorCode, NetworkError, MaintenanceError, HaspSDKError } = HaspSDK;

try {
  await sdk.createRecord('tasks', data);
} catch (error) {
  if (error instanceof DOMException && error.name === 'AbortError') {
    return;
  }
  if (error instanceof NetworkError) {
    showMessage('Check your internet connection.');
  } else if (error instanceof MaintenanceError) {
    showMessage('App is being updated. Try again shortly.');
  } else if (error instanceof HaspSDKError) {
    if (error.code === ErrorCode.ValidationFailed) {
      showFieldErrors(error.getFieldErrors());
    } else {
      showMessage(error.message);
    }
  }
}

ErrorCode Constants

ConstantValueWhen thrown
ErrorCode.UnauthorizedUNAUTHORIZEDSession expired
ErrorCode.AccessDeniedACCESS_DENIEDNo permission for this app or record
ErrorCode.MissingAppIdMISSING_APP_IDConstructor called without appId and window.__HASP__ not set
ErrorCode.NotFoundNOT_FOUNDRecord, entity, or app not found
ErrorCode.ReadOnlyRecordREAD_ONLY_RECORDRecord is read-only
ErrorCode.ValidationFailedVALIDATION_FAILEDField validation error — check getFieldErrors()
ErrorCode.StorageLimitReachedSTORAGE_LIMIT_REACHEDStorage quota exceeded
ErrorCode.RateLimitedRATE_LIMITEDToo many requests — retried automatically; throws if all retries exhausted
ErrorCode.QueryTooComplexQUERY_TOO_COMPLEXFilter is too deeply nested or complex
ErrorCode.MaintenanceMAINTENANCEApp is in maintenance mode
ErrorCode.NetworkErrorNETWORK_ERRORNetwork unreachable
ErrorCode.UnknownUNKNOWNUnexpected server error

Validation Field Errors

When error.code === ErrorCode.ValidationFailed, call error.getFieldErrors() to get a { fieldKey: 'message' } map of the first error per field:
const fieldErrors = error.getFieldErrors();
// { title: 'This field is required.', status: 'Invalid value.' }

Object.entries(fieldErrors).forEach(([field, message]) => {
  const el = document.getElementById(`error-${field}`);
  if (el) el.textContent = message;
});

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.