Skip to content

Commit

Permalink
Throw -> error code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael committed Feb 9, 2019
1 parent cfe4e6e commit cdc6781
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/connectLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,19 @@ const connectLib = function(ff: Function) {
const config = this.config
const ws = config.socket || config.adapter(`ws://${config.url}`, config.protocols)
this.ws = ws

if(!ws || ws.readyState > 1) {
this.ws = null
this.log('Error: ready() on closing or closed state! Status 2.')
return ff(2)
}

add_event(ws, 'error', once(() => {
this.ws = null
this.log('Error status 3.')
// Some network error: Connection refused or so.
return ff(3)
}))

if(!ws || ws.readyState > 1) {
throw new Error('WSP: Error: ready() on closing or closed state!')
}
// Because 'open' won't be envoked on opened socket.
if(ws.readyState) {
init.call(this, ws)
Expand Down

0 comments on commit cdc6781

Please sign in to comment.