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;
}| Property | Description |
|---|---|
lastError | The most recent error, or null |
clearError | Dismiss the current error |
isRecovering | true 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_MISMATCHerror 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_EXCEEDEDis stored - The user can dismiss the error and attempt to reconnect manually
Error Codes
| Code | Recoverable | Description |
|---|---|---|
MAX_RETRIES_EXCEEDED | Yes | WebSocket failed to reconnect after 5 attempts |
SESSION_MISMATCH | No | Server session has diverged; full reload required |
AUTH_FAILED | No | Authentication token is invalid or expired |
FORBIDDEN | No | User lacks required permissions |