Skip to content
This repository was archived by the owner on Feb 26, 2021. It is now read-only.

Commit ca08c48

Browse files
committed
fix: better ws errors
1 parent 7e2b894 commit ca08c48

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/errors/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
exports.ERR_WS_STAR_WEBSOCKET_CONNECTION = 'ERR_WS_STAR_WEBSOCKET_CONNECTION'

src/listener.js

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const setImmediate = require('async/setImmediate')
1414
const utils = require('./utils')
1515
const cleanUrlSIO = utils.cleanUrlSIO
1616
const crypto = require('libp2p-crypto')
17+
const ERRORS = require('./errors')
1718

1819
const noop = once(() => {})
1920

@@ -214,6 +215,15 @@ class Listener extends EE {
214215
(cb) => this._crypto(cb)
215216
], (err) => {
216217
if (err) {
218+
// Error connecting to WebSocket
219+
if (err.description && err.description.code === 'ENOTFOUND') {
220+
const hostname = err.description.hostname
221+
222+
err = Object.assign(new Error(`WebSocket connection failed on ${hostname}`), {
223+
code: ERRORS.ERR_WS_STAR_WEBSOCKET_CONNECTION
224+
})
225+
}
226+
217227
this.log('error', err)
218228
if (!(err instanceof Error)) err = new Error(err)
219229
this._down()

0 commit comments

Comments
 (0)