From f682ddefa365a0e2cf489328537ba39442f0b5a7 Mon Sep 17 00:00:00 2001 From: cgeek <cem.moreau@gmail.com> Date: Sat, 5 Jan 2019 18:18:54 +0100 Subject: [PATCH] [enh] #1326 Spread connection error message --- app/modules/crawler/lib/sync.ts | 1 + app/modules/crawler/lib/sync/RemoteSynchronizer.ts | 1 + app/modules/crawler/lib/sync/Watcher.ts | 13 +++++++++++++ 3 files changed, 15 insertions(+) diff --git a/app/modules/crawler/lib/sync.ts b/app/modules/crawler/lib/sync.ts index 9b28381c9..69f6f21b8 100644 --- a/app/modules/crawler/lib/sync.ts +++ b/app/modules/crawler/lib/sync.ts @@ -58,6 +58,7 @@ export class Synchroniser extends stream.Duplex { this.watcher.onEvent('wantToLoad', (data) => this.push({ p2pData: { name: 'wantToLoad', data }})) this.watcher.onEvent('beforeReadyNodes', (data) => this.push({ p2pData: { name: 'beforeReadyNodes', data }})) this.watcher.onEvent('syncFailNoNodeFound', (data) => this.push({ p2pData: { name: 'syncFailNoNodeFound', data }})) + this.watcher.onEvent('syncFailCannotConnectToRemote', (data) => this.push({ p2pData: { name: 'syncFailCannotConnectToRemote', data }})) this.syncStrategy.setWatcher(this.watcher) diff --git a/app/modules/crawler/lib/sync/RemoteSynchronizer.ts b/app/modules/crawler/lib/sync/RemoteSynchronizer.ts index 7916d0c01..e18e1f4fa 100644 --- a/app/modules/crawler/lib/sync/RemoteSynchronizer.ts +++ b/app/modules/crawler/lib/sync/RemoteSynchronizer.ts @@ -101,6 +101,7 @@ export class RemoteSynchronizer extends AbstractSynchronizer { async init(): Promise<void> { const syncApi = await RemoteSynchronizer.getSyncAPI([{ host: this.host, port: this.port }], this.server.conf.pair) if (!syncApi.api) { + this.watcher.syncFailCannotConnectToRemote() throw Error(DataErrors[DataErrors.CANNOT_CONNECT_TO_REMOTE_FOR_SYNC]) } this.currency = syncApi.currency diff --git a/app/modules/crawler/lib/sync/Watcher.ts b/app/modules/crawler/lib/sync/Watcher.ts index 3bc8cb0df..3679f8f87 100644 --- a/app/modules/crawler/lib/sync/Watcher.ts +++ b/app/modules/crawler/lib/sync/Watcher.ts @@ -32,6 +32,8 @@ export interface Watcher { beforeReadyNodes(p2pCandidates: P2pCandidate[]): void syncFailNoNodeFound(): void + + syncFailCannotConnectToRemote(): void } export type EventName = 'downloadChange'|'storageChange'|'appliedChange'|'sbxChange'|'peersChange' @@ -45,6 +47,7 @@ export type EventName = 'downloadChange'|'storageChange'|'appliedChange'|'sbxCha | 'wantToLoad' | 'beforeReadyNodes' | 'syncFailNoNodeFound' + | 'syncFailCannotConnectToRemote' export class EventWatcher extends events.EventEmitter implements Watcher { @@ -142,6 +145,10 @@ export class EventWatcher extends events.EventEmitter implements Watcher { syncFailNoNodeFound(): void { this.emit('syncFailNoNodeFound', {}) } + + syncFailCannotConnectToRemote(): void { + this.emit('syncFailCannotConnectToRemote', {}) + } } export class MultimeterWatcher implements Watcher { @@ -282,6 +289,9 @@ export class MultimeterWatcher implements Watcher { syncFailNoNodeFound(): void { } + syncFailCannotConnectToRemote(): void { + } + } export class LoggerWatcher implements Watcher { @@ -377,4 +387,7 @@ export class LoggerWatcher implements Watcher { syncFailNoNodeFound(): void { } + syncFailCannotConnectToRemote(): void { + } + } -- GitLab