Skip to content

Commit

Permalink
fix(socket-errors): moving isconnecting logic into disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
BLuEScioN committed Apr 25, 2024
1 parent ad46eda commit 4741e3d
Showing 1 changed file with 1 addition and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function useStacksApiSocketClient(apiUrl: string): StacksApiSocketClientI
socketClient?.socket.removeAllListeners();
socketClient?.socket.close();
setSocketClient(null);
isSocketClientConnecting.current = false;

Check warning on line 23 in src/app/_components/BlockList/Sockets/use-stacks-api-socket-client.ts

View check run for this annotation

Codecov / codecov/patch

src/app/_components/BlockList/Sockets/use-stacks-api-socket-client.ts#L20-L23

Added lines #L20 - L23 were not covered by tests
}
}, [socketClient]);

Expand All @@ -38,24 +39,20 @@ export function useStacksApiSocketClient(apiUrl: string): StacksApiSocketClientI
client.socket.on('connect', () => {
setSocketClient(client);
handleOnConnect?.(client);
isSocketClientConnecting.current = false;
});
client.socket.on('disconnect', () => {
client.socket.removeAllListeners();
client.socket.close();
disconnect();

Check warning on line 46 in src/app/_components/BlockList/Sockets/use-stacks-api-socket-client.ts

View check run for this annotation

Codecov / codecov/patch

src/app/_components/BlockList/Sockets/use-stacks-api-socket-client.ts#L44-L46

Added lines #L44 - L46 were not covered by tests
isSocketClientConnecting.current = false;
});
client.socket.on('connect_error', error => {
client.socket.removeAllListeners();
client.socket.close();
disconnect();
isSocketClientConnecting.current = false;
handleError?.(client);

Check warning on line 52 in src/app/_components/BlockList/Sockets/use-stacks-api-socket-client.ts

View check run for this annotation

Codecov / codecov/patch

src/app/_components/BlockList/Sockets/use-stacks-api-socket-client.ts#L49-L52

Added lines #L49 - L52 were not covered by tests
});
} catch (error) {
disconnect();

Check warning on line 55 in src/app/_components/BlockList/Sockets/use-stacks-api-socket-client.ts

View check run for this annotation

Codecov / codecov/patch

src/app/_components/BlockList/Sockets/use-stacks-api-socket-client.ts#L55

Added line #L55 was not covered by tests
isSocketClientConnecting.current = false;
}
},
[apiUrl, socketClient, disconnect]
Expand Down

0 comments on commit 4741e3d

Please sign in to comment.