From 11b6e3b1a3f979ab401b04ea1e26ad6d10a5f321 Mon Sep 17 00:00:00 2001 From: Adhiraj Date: Tue, 25 Aug 2020 22:21:49 +0530 Subject: [PATCH] Update 3.Connect.ts --- src/WAConnection/3.Connect.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/WAConnection/3.Connect.ts b/src/WAConnection/3.Connect.ts index cebe4b4..898656d 100644 --- a/src/WAConnection/3.Connect.ts +++ b/src/WAConnection/3.Connect.ts @@ -16,7 +16,7 @@ export class WAConnection extends Base { this.emit ('connecting') const { ws, cancel } = Utils.openWebSocketConnection (5000, typeof options?.retryOnNetworkErrors === 'undefined' ? true : options?.retryOnNetworkErrors) - const promise: Promise = Utils.promiseTimeout(options?.timeoutMs, (resolve, reject) => { + const promise = Utils.promiseTimeout(options?.timeoutMs, (resolve, reject) => { ws .then (conn => this.conn = conn) .then (() => this.conn.on('message', data => this.onMessageRecieved(data as any))) @@ -29,11 +29,12 @@ export class WAConnection extends Base { this.conn.on ('close', () => this.unexpectedDisconnect ('close')) }) .then (resolve) - .catch (err => { - cancel () - reject (err) - }) + .catch (reject) }) + .catch (err => { + cancel () + throw err + }) as Promise try { const tasks = [promise]