diff --git a/frontend/sync-client/src/services/sync-service.ts b/frontend/sync-client/src/services/sync-service.ts index 0b3fcba3..0d18e4bd 100644 --- a/frontend/sync-client/src/services/sync-service.ts +++ b/frontend/sync-client/src/services/sync-service.ts @@ -18,6 +18,7 @@ export interface CheckConnectionResult { } export class SyncService { + private static readonly NETWORK_RETRY_INTERVAL_MS = 1000; private client: Client; private pingClient: Client; private _fetchImplementation: typeof globalThis.fetch = globalThis.fetch; @@ -244,47 +245,27 @@ export class SyncService { }); } - public async getAll( - since?: VaultUpdateId - ): Promise { - return this.withRetries(async () => { - const { vaultName } = this.settings.getSettings(); - - const response = await this.client.GET( - "/vaults/{vault_id}/documents", - { - params: { - path: { - vault_id: vaultName - }, - header: { - authorization: `Bearer ${this.settings.getSettings().token}` - }, - query: { - since_update_id: since - } + public async checkConnection(): Promise { + try { + const response = await this.pingClient.GET("/ping", { + params: { + header: { + authorization: `Bearer ${this.settings.getSettings().token}` } } + }); + + this.logger.debug( + `Ping response: ${JSON.stringify(response.data)}` ); - const { error } = response; - if (error) { + if (!response.data) { throw new Error( - `Failed to get documents: ${SyncService.formatError(response.error)}` + `Failed to ping server: ${SyncService.formatError(response.error)}` ); } - this.logger.debug( - `Got ${response.data.latestDocuments.length} document metadata` - ); - - return response.data; - }); - } - - public async checkConnection(): Promise { - try { - const result = await this.ping(); + const result = response.data; if (result.isAuthenticated) { return { isSuccessful: true, @@ -304,27 +285,6 @@ export class SyncService { } } - // No retries - private async ping(): Promise { - const response = await this.pingClient.GET("/ping", { - params: { - header: { - authorization: `Bearer ${this.settings.getSettings().token}` - } - } - }); - - this.logger.debug(`Ping response: ${JSON.stringify(response.data)}`); - - if (!response.data) { - throw new Error( - `Failed to ping server: ${SyncService.formatError(response.error)}` - ); - } - - return response.data; - } - /** * Create a client and a ping client for the given remote URI. */ @@ -355,8 +315,10 @@ export class SyncService { throw e; } - this.logger.error(`Failed network call (${e}), retrying`); - await sleep(1000); + this.logger.error( + `Failed network call (${e}), retryingin ${SyncService.NETWORK_RETRY_INTERVAL_MS}ms` + ); + await sleep(SyncService.NETWORK_RETRY_INTERVAL_MS); } } }