Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nodes): can't login when no online nodes available #571

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(nodes): can't login when no online nodes available
bludnic committed Dec 21, 2023
commit 4d2a3964cca260e7458450a1afd0d6a30ea6c41b
5 changes: 4 additions & 1 deletion src/lib/nodes/abstract.client.ts
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion src/lib/nodes/utils/filterSyncedNodes.ts
Original file line number Diff line number Diff line change
@@ -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