Skip to content

Commit

Permalink
fix(nodes): can't login when no online nodes available
Browse files Browse the repository at this point in the history
  • Loading branch information
bludnic committed Dec 21, 2023
1 parent 7469103 commit 4d2a396
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/lib/nodes/abstract.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export abstract class Client<N extends Node> {
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
Expand Down
5 changes: 4 additions & 1 deletion src/lib/nodes/utils/filterSyncedNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ type GroupNodes<N extends Node> = {
*/
export function filterSyncedNodes<N extends Node>(nodes: N[]): GroupNodes<N> {
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
Expand Down

0 comments on commit 4d2a396

Please sign in to comment.