From b8fd583610c13d23aa9a8f3778d765e2691807dd Mon Sep 17 00:00:00 2001 From: Herman Bilous Date: Tue, 7 Feb 2023 16:46:55 +0200 Subject: [PATCH] Provide more context to ConnectionError when connecting to a room (#575) * Provide more context to ConnectionError when connecting to a room * Fix prettier issues * Create mighty-boats-wonder.md --------- Co-authored-by: lukasIO --- .changeset/mighty-boats-wonder.md | 5 +++++ src/room/Room.ts | 12 ++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 .changeset/mighty-boats-wonder.md diff --git a/.changeset/mighty-boats-wonder.md b/.changeset/mighty-boats-wonder.md new file mode 100644 index 0000000000..2a389dc6ea --- /dev/null +++ b/.changeset/mighty-boats-wonder.md @@ -0,0 +1,5 @@ +--- +"livekit-client": patch +--- + +Provide more context to ConnectionError when connecting to a room diff --git a/src/room/Room.ts b/src/room/Room.ts index 08febe1cb0..b3b3080b38 100644 --- a/src/room/Room.ts +++ b/src/room/Room.ts @@ -355,12 +355,16 @@ class Room extends (EventEmitter as new () => TypedEmitter) } catch (err) { this.recreateEngine(); this.handleDisconnect(this.options.stopLocalTrackOnUnpublish); - let errorMessage = ''; + const resultingError = new ConnectionError(`could not establish signal connection`); if (err instanceof Error) { - errorMessage = err.message; - log.debug(`error trying to establish signal connection`, { error: err }); + resultingError.message = `${resultingError.message}: ${err.message}`; } - reject(new ConnectionError(`could not establish signal connection: ${errorMessage}`)); + if (err instanceof ConnectionError) { + resultingError.reason = err.reason; + resultingError.status = err.status; + } + log.debug(`error trying to establish signal connection`, { error: err }); + reject(resultingError); return; }