Skip to content

Commit 8b22571

Browse files
committed
fix(v3.1.3, #600): handle risk of circular reference in WS API Client exception handler
1 parent b7924a6 commit 8b22571

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "binance",
3-
"version": "3.1.2",
3+
"version": "3.1.3",
44
"description": "Professional Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & end-to-end tests.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/types/websockets/ws-general.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { AxiosRequestConfig } from 'axios';
2+
import { ClientRequestArgs } from 'http';
23
import WebSocket from 'isomorphic-ws';
34

45
import { RestClientOptions } from '../../util/requestUtils';
@@ -168,7 +169,7 @@ export interface WSClientConfigurableOptions {
168169
wsOptions?: {
169170
protocols?: string[];
170171
agent?: any;
171-
};
172+
} & Partial<WebSocket.ClientOptions | ClientRequestArgs>;
172173

173174
wsUrl?: string;
174175

src/websocket-api-client.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,17 @@ export class WebsocketAPIClient {
12371237
console.info(new Date(), 'ws has authenticated ', data?.wsKey);
12381238
})
12391239
.on('exception', (data) => {
1240-
console.error(new Date(), 'ws exception: ', JSON.stringify(data));
1240+
try {
1241+
// Blind JSON.stringify can fail on circular references
1242+
console.error(
1243+
new Date(),
1244+
'ws exception: ',
1245+
JSON.stringify(data),
1246+
// JSON.stringify({ ...data, target: 'WebSocket' }),
1247+
);
1248+
} catch {
1249+
console.error(new Date(), 'ws exception: ', data);
1250+
}
12411251
});
12421252
}
12431253
}

0 commit comments

Comments
 (0)