Skip to content

Commit 22c4c59

Browse files
Peter Wilhelmsson2hdddg
Peter Wilhelmsson
authored andcommitted
Catch error on send to propagate to standard error handler
1 parent 2a6d4af commit 22c4c59

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/internal/browser/browser-channel.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,17 @@ export default class WebSocketChannel {
134134
if (this._pending !== null) {
135135
this._pending.push(buffer)
136136
} else if (buffer instanceof HeapBuffer) {
137-
this._ws.send(buffer._buffer)
137+
try {
138+
this._ws.send(buffer._buffer)
139+
} catch (error) {
140+
if (this._ws.readyState !== WS_OPEN) {
141+
// Websocket has been closed
142+
this._handleConnectionError()
143+
} else {
144+
// Some other error occured
145+
throw error
146+
}
147+
}
138148
} else {
139149
throw newError("Don't know how to send buffer: " + buffer)
140150
}

0 commit comments

Comments
 (0)