Skip to content

Commit c305232

Browse files
author
Nedunchezhiyan-M
committed
Improve WebSocket error messages for CONNECTING state
The send() and ping() methods throw "INVALID_STATE_ERR" which is an opaque error code that doesn't tell the developer what went wrong. Updated to descriptive messages that explain the actual issue, matching the style used by browser WebSocket implementations.
1 parent 8bac1df commit c305232

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/react-native/Libraries/WebSocket/WebSocket.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ class WebSocket extends EventTarget {
181181

182182
send(data: string | ArrayBuffer | ArrayBufferView | Blob): void {
183183
if (this.readyState === this.CONNECTING) {
184-
throw new Error('INVALID_STATE_ERR');
184+
throw new Error(
185+
"Failed to execute 'send' on 'WebSocket': Still in CONNECTING state",
186+
);
185187
}
186188

187189
if (data instanceof Blob) {
@@ -208,7 +210,9 @@ class WebSocket extends EventTarget {
208210

209211
ping(): void {
210212
if (this.readyState === this.CONNECTING) {
211-
throw new Error('INVALID_STATE_ERR');
213+
throw new Error(
214+
"Failed to execute 'ping' on 'WebSocket': Still in CONNECTING state",
215+
);
212216
}
213217

214218
NativeWebSocketModule.ping(this._socketId);

0 commit comments

Comments
 (0)