added proper connection check

This commit is contained in:
2026-04-08 15:09:08 -05:00
parent fd625a7420
commit 00eeff1282
2 changed files with 8 additions and 8 deletions
+4 -4
View File
@@ -24,7 +24,7 @@ export class TetherClient {
}; };
}; };
disconnect = () => { disconnect = () => {
if (!this.ws) { if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
throw new Error('Not connected to Tether'); throw new Error('Not connected to Tether');
} }
this.ws.close(); this.ws.close();
@@ -32,7 +32,7 @@ export class TetherClient {
}; };
subscribe = (query, callback) => { subscribe = (query, callback) => {
this.subscribedQueries.set(query, callback); this.subscribedQueries.set(query, callback);
if (!this.ws) { if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
throw new Error('Not connected to Tether'); throw new Error('Not connected to Tether');
} }
this.ws.send(JSON.stringify({ this.ws.send(JSON.stringify({
@@ -42,7 +42,7 @@ export class TetherClient {
}; };
unsubscribe = (query) => { unsubscribe = (query) => {
this.subscribedQueries.delete(query); this.subscribedQueries.delete(query);
if (!this.ws) { if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
throw new Error('Not connected to Tether'); throw new Error('Not connected to Tether');
} }
this.ws.send(JSON.stringify({ this.ws.send(JSON.stringify({
@@ -51,7 +51,7 @@ export class TetherClient {
})); }));
}; };
sendMutation = (mutationName, params) => { sendMutation = (mutationName, params) => {
if (!this.ws) { if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
throw new Error('Not connected to Tether'); throw new Error('Not connected to Tether');
} }
this.ws.send(JSON.stringify({ this.ws.send(JSON.stringify({
+4 -4
View File
@@ -25,7 +25,7 @@ export class TetherClient {
}; };
disconnect = () => { disconnect = () => {
if (!this.ws) { if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
throw new Error('Not connected to Tether'); throw new Error('Not connected to Tether');
} }
this.ws.close(); this.ws.close();
@@ -34,7 +34,7 @@ export class TetherClient {
subscribe = (query: string, callback: (data: any) => void) => { subscribe = (query: string, callback: (data: any) => void) => {
this.subscribedQueries.set(query, callback); this.subscribedQueries.set(query, callback);
if (!this.ws) { if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
throw new Error('Not connected to Tether'); throw new Error('Not connected to Tether');
} }
this.ws.send(JSON.stringify({ this.ws.send(JSON.stringify({
@@ -45,7 +45,7 @@ export class TetherClient {
unsubscribe = (query: string) => { unsubscribe = (query: string) => {
this.subscribedQueries.delete(query); this.subscribedQueries.delete(query);
if (!this.ws) { if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
throw new Error('Not connected to Tether'); throw new Error('Not connected to Tether');
} }
this.ws.send(JSON.stringify({ this.ws.send(JSON.stringify({
@@ -55,7 +55,7 @@ export class TetherClient {
}; };
sendMutation = (mutationName: string, params: any) => { sendMutation = (mutationName: string, params: any) => {
if (!this.ws) { if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
throw new Error('Not connected to Tether'); throw new Error('Not connected to Tether');
} }
this.ws.send(JSON.stringify({ this.ws.send(JSON.stringify({