Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
feat: enable return error from getSyncStatus (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpuente authored Sep 4, 2024
1 parent ffc5476 commit fcd3508
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './server';
export * from './server/error';
export * from './storage';
export * from './utils';
9 changes: 9 additions & 0 deletions src/server/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
15 changes: 10 additions & 5 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ import { logger } from '../utils/logger';
import {
ConflictOperationError,
DriveAlreadyExistsError,
OperationError
OperationError,
SynchronizationUnitNotFoundError
} from './error';
import { ListenerManager } from './listener/manager';
import {
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions src/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -361,7 +361,9 @@ export abstract class BaseDocumentDriveServer {
options?: AddOperationOptions
): Promise<IOperationResult<DocumentDriveDocument>>;

abstract getSyncStatus(drive: string): SyncStatus;
abstract getSyncStatus(
syncUnitId: string
): SyncStatus | SynchronizationUnitNotFoundError;

/** Synchronization methods */
abstract getSynchronizationUnits(
Expand Down

0 comments on commit fcd3508

Please sign in to comment.