Skip to content

Commit

Permalink
Merge pull request #571 from Adamant-im/fix/login-error-when-no-onlin…
Browse files Browse the repository at this point in the history
…e-nodes

fix(nodes): can't login when no online nodes available
  • Loading branch information
bludnic authored Dec 22, 2023
2 parents 0d935bb + 4d2a396 commit c2b2c2b
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 c2b2c2b

Please sign in to comment.