From faa7c57ade57a788cf406bc414bc6df4638c1a20 Mon Sep 17 00:00:00 2001 From: Diogo Silva Date: Tue, 19 Jun 2018 14:12:32 +0100 Subject: [PATCH] fix: better ws errors --- src/errors/index.js | 3 +++ src/listener.js | 10 ++++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/errors/index.js diff --git a/src/errors/index.js b/src/errors/index.js new file mode 100644 index 0000000..ccfea7a --- /dev/null +++ b/src/errors/index.js @@ -0,0 +1,3 @@ +'use strict' + +exports.ERR_WS_STAR_WEBSOCKET_CONNECTION = 'ERR_WS_STAR_WEBSOCKET_CONNECTION' diff --git a/src/listener.js b/src/listener.js index 679187b..bf93428 100644 --- a/src/listener.js +++ b/src/listener.js @@ -15,6 +15,7 @@ const utils = require('./utils') const cleanUrlSIO = utils.cleanUrlSIO const crypto = require('libp2p-crypto') const pull = require('pull-stream') +const ERRORS = require('./errors') const noop = once(() => {}) @@ -222,6 +223,15 @@ class Listener extends EE { (cb) => this._crypto(cb) ], (err) => { if (err) { + // Error connecting to WebSocket + if (err.description && err.description.code === 'ENOTFOUND') { + const hostname = err.description.hostname + + err = Object.assign(new Error(`WebSocket connection failed on ${hostname}`), { + code: ERRORS.ERR_WS_STAR_WEBSOCKET_CONNECTION + }) + } + this.log('error', err) if (!(err instanceof Error)) err = new Error(err) this._down()