UNPKG

@tldraw/sync-core

Version:

tldraw infinite canvas SDK (multiplayer sync).

8 lines (7 loc) 2.31 kB
{ "version": 3, "sources": ["../../src/lib/TLRemoteSyncError.ts"], "sourcesContent": ["import { TLSyncErrorCloseEventReason } from './TLSyncClient'\n\n/**\n * Specialized error class for synchronization-related failures in tldraw collaboration.\n *\n * This error is thrown when the sync client encounters fatal errors that prevent\n * successful synchronization with the server. It captures both the error message\n * and the specific reason code that triggered the failure.\n *\n * Common scenarios include schema version mismatches, authentication failures,\n * network connectivity issues, and server-side validation errors.\n *\n * @example\n * ```ts\n * import { TLRemoteSyncError, TLSyncErrorCloseEventReason } from '@tldraw/sync-core'\n *\n * // Handle sync errors in your application\n * syncClient.onSyncError((error) => {\n * if (error instanceof TLRemoteSyncError) {\n * switch (error.reason) {\n * case TLSyncErrorCloseEventReason.NOT_AUTHENTICATED:\n * // Redirect user to login\n * break\n * case TLSyncErrorCloseEventReason.CLIENT_TOO_OLD:\n * // Show update required message\n * break\n * default:\n * console.error('Sync error:', error.message)\n * }\n * }\n * })\n * ```\n *\n * @example\n * ```ts\n * // Server-side: throwing a sync error\n * if (!hasPermission(userId, roomId)) {\n * throw new TLRemoteSyncError(TLSyncErrorCloseEventReason.FORBIDDEN)\n * }\n * ```\n *\n * @public\n */\nexport class TLRemoteSyncError extends Error {\n\toverride name = 'RemoteSyncError'\n\n\t/**\n\t * Creates a new TLRemoteSyncError with the specified reason.\n\t *\n\t * reason - The specific reason code or custom string describing why the sync failed.\n\t * When using predefined reasons from TLSyncErrorCloseEventReason, the client\n\t * can handle specific error types appropriately. Custom strings allow for\n\t * application-specific error details.\n\t */\n\tconstructor(public readonly reason: TLSyncErrorCloseEventReason | string) {\n\t\tsuper(`sync error: ${reason}`)\n\t}\n}\n"], "mappings": "AA2CO,MAAM,0BAA0B,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW5C,YAA4B,QAA8C;AACzE,UAAM,eAAe,MAAM,EAAE;AADF;AAAA,EAE5B;AAAA,EAZS,OAAO;AAajB;", "names": [] }