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

Commit

Permalink
fix: better ws errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fsdiogo authored and jacobheun committed Oct 2, 2018
1 parent 9953f95 commit faa7c57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/errors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

exports.ERR_WS_STAR_WEBSOCKET_CONNECTION = 'ERR_WS_STAR_WEBSOCKET_CONNECTION'
10 changes: 10 additions & 0 deletions src/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {})

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit faa7c57

Please sign in to comment.