diff --git a/src/index.ts b/src/index.ts index 25c5a9e..6c3bc8d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ export * from './server'; +export * from './server/error'; export * from './storage'; export * from './utils'; diff --git a/src/server/error.ts b/src/server/error.ts index 27008a5..0bf2979 100644 --- a/src/server/error.ts +++ b/src/server/error.ts @@ -51,3 +51,12 @@ export class DriveNotFoundError extends Error { this.driveId = driveId; } } + +export class SynchronizationUnitNotFoundError extends Error { + syncUnitId: string; + + constructor(message: string, syncUnitId: string) { + super(message); + this.syncUnitId = syncUnitId; + } +} diff --git a/src/server/index.ts b/src/server/index.ts index a0d8457..7b206d7 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -58,7 +58,8 @@ import { logger } from '../utils/logger'; import { ConflictOperationError, DriveAlreadyExistsError, - OperationError + OperationError, + SynchronizationUnitNotFoundError } from './error'; import { ListenerManager } from './listener/manager'; import { @@ -2304,11 +2305,15 @@ export class DocumentDriveServer extends BaseDocumentDriveServer { return this.listenerStateManager.getListener(driveId, listenerId); } - getSyncStatus(drive: string): SyncStatus { - const status = this.syncStatus.get(drive); + getSyncStatus( + syncUnitId: string + ): SyncStatus | SynchronizationUnitNotFoundError { + const status = this.syncStatus.get(syncUnitId); if (!status) { - logger.error(`Sync status not found for drive ${drive}`); - throw new Error(`Sync status not found for drive ${drive}`); + return new SynchronizationUnitNotFoundError( + `Sync status not found for syncUnitId: ${syncUnitId}`, + syncUnitId + ); } return this.getCombinedSyncUnitStatus(status); } diff --git a/src/server/types.ts b/src/server/types.ts index 2b877b8..6e51869 100644 --- a/src/server/types.ts +++ b/src/server/types.ts @@ -21,7 +21,7 @@ import type { } from 'document-model/document'; import { Unsubscribe } from 'nanoevents'; import { DriveInfo } from '../utils/graphql'; -import { OperationError } from './error'; +import { OperationError, SynchronizationUnitNotFoundError } from './error'; import { ITransmitter, PullResponderTrigger, @@ -361,7 +361,9 @@ export abstract class BaseDocumentDriveServer { options?: AddOperationOptions ): Promise>; - abstract getSyncStatus(drive: string): SyncStatus; + abstract getSyncStatus( + syncUnitId: string + ): SyncStatus | SynchronizationUnitNotFoundError; /** Synchronization methods */ abstract getSynchronizationUnits(