@@ -105,7 +105,7 @@ function establishWebSocketConnection (url, protocols, client, handler, options)
105105 // 1. If response is a network error or its status is not 101,
106106 // fail the WebSocket connection.
107107 if ( response . type === 'error' || response . status !== 101 ) {
108- failWebsocketConnection ( handler , 1002 , 'Received network error or non-101 status code.' )
108+ failWebsocketConnection ( handler , 1002 , 'Received network error or non-101 status code.' , response . error )
109109 return
110110 }
111111
@@ -298,9 +298,10 @@ function closeWebSocketConnection (object, code, reason, validate = false) {
298298 * @param {import('./websocket').Handler } handler
299299 * @param {number } code
300300 * @param {string|undefined } reason
301+ * @param {unknown } cause
301302 * @returns {void }
302303 */
303- function failWebsocketConnection ( handler , code , reason ) {
304+ function failWebsocketConnection ( handler , code , reason , cause ) {
304305 // If _The WebSocket Connection is Established_ prior to the point where
305306 // the endpoint is required to _Fail the WebSocket Connection_, the
306307 // endpoint SHOULD send a Close frame with an appropriate status code
@@ -315,7 +316,7 @@ function failWebsocketConnection (handler, code, reason) {
315316 handler . socket . destroy ( )
316317 }
317318
318- handler . onFail ( code , reason )
319+ handler . onFail ( code , reason , cause )
319320}
320321
321322module . exports = {
0 commit comments