diff --git a/frontend/sync-client/src/services/sync-reset-error.ts b/frontend/sync-client/src/services/sync-reset-error.ts index 5e27dfb6..3fd8a86c 100644 --- a/frontend/sync-client/src/services/sync-reset-error.ts +++ b/frontend/sync-client/src/services/sync-reset-error.ts @@ -1,6 +1,6 @@ export class SyncResetError extends Error { public constructor() { - super("Sync was reset"); + super("SyncClient has been reset, cleaning up"); this.name = "SyncResetError"; } } diff --git a/frontend/sync-client/src/services/sync-service.ts b/frontend/sync-client/src/services/sync-service.ts index 331f806c..8ae85b58 100644 --- a/frontend/sync-client/src/services/sync-service.ts +++ b/frontend/sync-client/src/services/sync-service.ts @@ -19,11 +19,6 @@ import type { DeleteDocumentVersion } from "./types/DeleteDocumentVersion"; import type { UpdateTextDocumentVersion } from "./types/UpdateTextDocumentVersion"; import { NETWORK_RETRY_INTERVAL_MS } from "../consts"; -export interface CheckConnectionResult { - isSuccessful: boolean; - message: string; -} - export class SyncService { private readonly client: typeof globalThis.fetch; private readonly pingClient: typeof globalThis.fetch; @@ -65,7 +60,7 @@ export class SyncService { relativePath: RelativePath; contentBytes: Uint8Array; }): Promise { - return this.withRetries(async () => { + return this.retryForever(async () => { const formData = new FormData(); if (documentId !== undefined) { formData.append("document_id", documentId); @@ -114,7 +109,7 @@ export class SyncService { relativePath: RelativePath; content: (number | string)[]; }): Promise { - return this.withRetries(async () => { + return this.retryForever(async () => { this.logger.debug( `Updating text document ${documentId} with parent version ${parentVersionId} and relative path ${relativePath}` ); @@ -166,7 +161,7 @@ export class SyncService { relativePath: RelativePath; contentBytes: Uint8Array; }): Promise { - return this.withRetries(async () => { + return this.retryForever(async () => { this.logger.debug( `Updating binary document ${documentId} with parent version ${parentVersionId} and relative path ${relativePath}` ); @@ -215,7 +210,7 @@ export class SyncService { documentId: DocumentId; relativePath: RelativePath; }): Promise { - return this.withRetries(async () => { + return this.retryForever(async () => { const request: DeleteDocumentVersion = { relativePath }; @@ -252,7 +247,7 @@ export class SyncService { }: { documentId: DocumentId; }): Promise { - return this.withRetries(async () => { + return this.retryForever(async () => { const response = await this.client( this.getUrl(`/documents/${documentId}`), { @@ -280,7 +275,7 @@ export class SyncService { public async getAll( since?: VaultUpdateId ): Promise { - return this.withRetries(async () => { + return this.retryForever(async () => { const url = new URL(this.getUrl("/documents")); if (since !== undefined) { url.searchParams.append("since", since.toString()); @@ -308,7 +303,10 @@ export class SyncService { }); } - public async checkConnection(): Promise { + public async checkConnection(): Promise<{ + isSuccessful: boolean; + message: string; + }> { try { const response = await this.pingClient(this.getUrl("/ping"), { headers: this.getDefaultHeaders() @@ -362,7 +360,7 @@ export class SyncService { return headers; } - private async withRetries(fn: () => Promise): Promise { + private async retryForever(fn: () => Promise): Promise { // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition while (true) { try {