From 4d2a3964cca260e7458450a1afd0d6a30ea6c41b Mon Sep 17 00:00:00 2001 From: bludnic Date: Thu, 21 Dec 2023 18:37:44 +0000 Subject: [PATCH] fix(nodes): can't login when no online nodes available --- src/lib/nodes/abstract.client.ts | 5 ++++- src/lib/nodes/utils/filterSyncedNodes.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/nodes/abstract.client.ts b/src/lib/nodes/abstract.client.ts index 6895317ab..1a91733fb 100644 --- a/src/lib/nodes/abstract.client.ts +++ b/src/lib/nodes/abstract.client.ts @@ -53,7 +53,10 @@ export abstract class Client { const node = this.useFastest ? this.getFastestNode() : this.getRandomNode() if (!node) { - throw new Error('No available nodes at the moment') + console.warn(`${this.type}: No online nodes at the moment`) + + // Return a random one from the full list hopefully is online + return this.nodes[Math.floor(Math.random() * this.nodes.length)].client } return node.client diff --git a/src/lib/nodes/utils/filterSyncedNodes.ts b/src/lib/nodes/utils/filterSyncedNodes.ts index a01564e33..ba176195f 100644 --- a/src/lib/nodes/utils/filterSyncedNodes.ts +++ b/src/lib/nodes/utils/filterSyncedNodes.ts @@ -22,7 +22,10 @@ type GroupNodes = { */ export function filterSyncedNodes(nodes: N[]): GroupNodes { if (nodes.length === 0) { - throw new Error('filterSyncedNodes: No nodes provided') + return { + height: 0, + nodes: [] + } } // For each node we take its height and list of nodes that have the same height ± epsilon