My App
BoardKitFrontend

useErrorRecovery

Error handling, stale tab detection, and automatic recovery

useErrorRecovery provides error state from the BoardStore and handles special recovery scenarios like concurrent page deletion and stale tab detection.

Signature

function useErrorRecovery(): UseErrorRecoveryResult;

Return Type

interface UseErrorRecoveryResult {
    lastError: BoardError | null;
    clearError: () => void;
    isRecovering: boolean;
}

interface BoardError {
    code: string;
    message: string;
    timestamp: number;
    recoverable: boolean;
}
PropertyDescription
lastErrorThe most recent error, or null
clearErrorDismiss the current error
isRecoveringtrue when automatic recovery is in progress

Usage

import { useErrorRecovery } from '@hfu.digital/boardkit-react';

function ErrorBanner() {
    const { lastError, clearError, isRecovering } = useErrorRecovery();

    if (!lastError) return null;

    return (
        <div role="alert">
            <p>{lastError.message}</p>
            {lastError.recoverable && (
                <button onClick={clearError}>Dismiss</button>
            )}
            {isRecovering && <span>Recovering...</span>}
        </div>
    );
}

Automatic Recovery Behaviors

Concurrent Page Deletion

When a remote participant deletes a page that the local user is viewing:

  • Selection is cleared
  • Active page switches to the first remaining page
  • This happens silently without showing an error

Stale Tab Detection

When the browser tab becomes visible again after being backgrounded:

  • If a SESSION_MISMATCH error exists, the hook triggers a full page reload to recover
  • This handles the case where the WebSocket reconnected but the session has diverged

Max Reconnect Attempts

When the WebSocket fails to reconnect after 5 attempts:

  • A recoverable error with code MAX_RETRIES_EXCEEDED is stored
  • The user can dismiss the error and attempt to reconnect manually

Error Codes

CodeRecoverableDescription
MAX_RETRIES_EXCEEDEDYesWebSocket failed to reconnect after 5 attempts
SESSION_MISMATCHNoServer session has diverged; full reload required
AUTH_FAILEDNoAuthentication token is invalid or expired
FORBIDDENNoUser lacks required permissions

On this page