From 79f6e56bf55cf81bea3a0ccbd67ff3074f7a9d22 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Thu, 7 Mar 2019 15:10:47 +0200 Subject: [PATCH] Handle websocket errors This prevents unhandled exception on websocket errors. It *doesn't* propagate the error, since the subscriber is internal, and it doesn't seem to do anything with it (like notifying the client via connectionStatus). Bug: #170 --- src/directLine.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/directLine.ts b/src/directLine.ts index 27c31e3fd..04363f472 100644 --- a/src/directLine.ts +++ b/src/directLine.ts @@ -849,6 +849,12 @@ export class DirectLine implements IBotConnection { ws.onmessage = message => message.data && subscriber.next(JSON.parse(message.data)); + ws.onerror = error => { + konsole.log("WebSocket error", error); + if (sub) sub.unsubscribe(); + subscriber.error(error); + } + // This is the 'unsubscribe' method, which is called when this observable is disposed. // When the WebSocket closes itself, we throw an error, and this function is eventually called. // When the observable is closed first (e.g. when tearing down a WebChat instance) then