Skip to content

Commit

Permalink
Catch errors on transport initialization when creating a Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
atoppi committed Nov 23, 2021
1 parent 6a592e3 commit cb14632
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,16 @@ class Connection extends EventEmitter {
send: async _ => { throw new Error('transport does not implement the "send" function'); },
getRemoteHostname: _ => { throw new Error('transport does not implement the "getRemoteHostname" function'); },
}
/* Check the protocol to define the kind of transport */
if (checkUrl(server_config.getAddress()[0].url, ['ws', 'wss'])) {
this._transport = new WsTransport(this);

try {
let transport;
/* Check the protocol to define the kind of transport */
if (checkUrl(server_config.getAddress()[0].url, ['ws', 'wss'])) {
transport = new WsTransport(this);
}
if (transport) this._transport = transport;
} catch (error) {
Logger.error(`${LOG_NS} ${this.name} error while initializing transport (${error.message})`);
}

/* Set a dummy error listener to avoid unmanaged errors */
Expand Down

0 comments on commit cb14632

Please sign in to comment.