bare-ws 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/errors.js +12 -2
- package/lib/socket.js +5 -0
- package/package.json +1 -1
package/lib/errors.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const { status } = require('./constants')
|
|
2
2
|
|
|
3
3
|
module.exports = class WebSocketError extends Error {
|
|
4
|
-
constructor(msg, code, status, fn = WebSocketError) {
|
|
5
|
-
super(`${code}: ${msg}
|
|
4
|
+
constructor(msg, code, status, fn = WebSocketError, cause) {
|
|
5
|
+
super(`${code}: ${msg}`, { cause })
|
|
6
6
|
this.code = code
|
|
7
7
|
this.status = status
|
|
8
8
|
|
|
@@ -15,6 +15,16 @@ module.exports = class WebSocketError extends Error {
|
|
|
15
15
|
return 'WebSocketError'
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
static NETWORK_ERROR(msg, cause) {
|
|
19
|
+
return new WebSocketError(
|
|
20
|
+
msg,
|
|
21
|
+
'NETWORK_ERROR',
|
|
22
|
+
0,
|
|
23
|
+
WebSocketError.NETWORK_ERROR,
|
|
24
|
+
cause
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
18
28
|
static NOT_CONNECTED(msg = 'Socket is not connected') {
|
|
19
29
|
return new WebSocketError(
|
|
20
30
|
msg,
|
package/lib/socket.js
CHANGED
|
@@ -234,6 +234,7 @@ module.exports = exports = class WebSocket extends Duplex {
|
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
_predestroy() {
|
|
237
|
+
if (!this._socket) return
|
|
237
238
|
this._socket.destroy()
|
|
238
239
|
}
|
|
239
240
|
}
|
|
@@ -270,6 +271,10 @@ const handshake = (exports.handshake = function handshake(req, cb) {
|
|
|
270
271
|
cb(null)
|
|
271
272
|
})
|
|
272
273
|
|
|
274
|
+
req.on('error', (err) => {
|
|
275
|
+
cb(errors.NETWORK_ERROR('Network error', err))
|
|
276
|
+
})
|
|
277
|
+
|
|
273
278
|
req.end()
|
|
274
279
|
})
|
|
275
280
|
|