Skip to main content
The SDK throws typed errors, all extending MindError. Import them and the type guards from @ulesson-education/mind-sdk:
import {
  MindError,
  MindApiError,
  StateTransitionError,
  ConfigurationError,
  isMindError,
  isMindApiError,
  isStateTransitionError,
  formatError,
} from '@ulesson-education/mind-sdk';

Error types

ErrorThrown when
ConfigurationErrorauthCookieKey is missing or empty, baseUrl is malformed, or the first updateContext lacks a pageType.
InitializationErrorMounting fails (already mounted, or container not found).
StateTransitionErrorAn invalid state transition is attempted.
ContextErrorContext is updated before it is initialized.
MindApiErrorThe API returns an error response.
NetworkErrorThe HTTP request fails before a response.

MindApiError helpers

MindApiError carries an HTTP status and code, plus helpers including isAuthError(), isRateLimitError(), isValidationError(), isServerError(), isRetryable(), and getValidationErrors():
try {
  await widget.triggerAction('talk-to-advisor');
} catch (error) {
  if (isMindApiError(error)) {
    if (error.isAuthError()) {
      // re-authenticate
    } else if (error.isRetryable()) {
      // back off and retry
    }
  }
  console.error(formatError(error));
}
You can also surface SDK errors centrally through config.hooks.onError. See Events and hooks.

Auth failure (401)

When any SDK HTTP request receives a 401, the widget hides itself by calling widget.hide() and emits an authFailed event. The SDK does not refresh the session — restoring it is the host app’s job. After the host re-establishes the session cookie, call widget.show() to bring the widget back.
widget.on("authFailed", () => {
  // The widget is now hidden. Kick off your re-auth flow, then:
  // await yourLoginFlow();
  // widget.show();
});