From c038c07b06dba0d25d9d4ecf20bcffa7b0dc8d81 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Tue, 28 Feb 2023 12:34:54 -0800 Subject: [PATCH] Better way to throw websocket exceptions --- ts/textsecure/Errors.ts | 3 ++- ts/textsecure/WebSocket.ts | 17 ++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ts/textsecure/Errors.ts b/ts/textsecure/Errors.ts index 06e3065557e..8d090128e62 100644 --- a/ts/textsecure/Errors.ts +++ b/ts/textsecure/Errors.ts @@ -33,9 +33,10 @@ export class HTTPError extends Error { headers: HTTPErrorHeadersType; response?: unknown; stack?: string; + cause?: unknown; } ) { - super(`${message}; code: ${options.code}`); + super(`${message}; code: ${options.code}`, { cause: options.cause }); const { code: providedCode, headers, response, stack } = options; diff --git a/ts/textsecure/WebSocket.ts b/ts/textsecure/WebSocket.ts index 2b361269b36..3a0dc19caf3 100644 --- a/ts/textsecure/WebSocket.ts +++ b/ts/textsecure/WebSocket.ts @@ -100,17 +100,16 @@ export function connect({ reject(translatedError); }); - client.on('connectFailed', e => { + client.on('connectFailed', originalErr => { Timers.clearTimeout(timer); - reject( - new HTTPError('connectResource: connectFailed', { - code: -1, - headers: {}, - response: e.toString(), - stack, - }) - ); + const err = new HTTPError('connectResource: connectFailed', { + code: -1, + headers: {}, + stack, + cause: originalErr, + }); + reject(err); }); return new AbortableProcess(