From 824aedc8358aada5417a7930a9d47285c5652160 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Thu, 14 Mar 2019 14:45:49 +0200 Subject: [PATCH] Avoid posting an error on intentional end Commit 544e7e328943f98d3ef2aa14404193ca08ab225f suppressed the exception, but it is still reported as an error. directLine.activity$ .filter(activity => activity.type === 'message') .subscribe( message => { console.log("received message ", message) directLine.end(); }, err => console.error // error is logged here ); --- src/directLine.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/directLine.ts b/src/directLine.ts index 27c31e3fd..0a7d82bc8 100644 --- a/src/directLine.ts +++ b/src/directLine.ts @@ -408,6 +408,8 @@ export class DirectLine implements IBotConnection { private tokenRefreshSubscription: Subscription; + private ending: boolean; + constructor(options: DirectLineOptions) { this.secret = options.secret; this.token = options.secret || options.token; @@ -493,7 +495,10 @@ export class DirectLine implements IBotConnection { .flatMap(connectionStatus => { switch (connectionStatus) { case ConnectionStatus.Ended: - return Observable.throw(errorConversationEnded); + if (this.ending) + return Observable.of(connectionStatus); + else + return Observable.throw(errorConversationEnded); case ConnectionStatus.FailedToConnect: return Observable.throw(errorFailedToConnect); @@ -617,13 +622,8 @@ export class DirectLine implements IBotConnection { end() { if (this.tokenRefreshSubscription) this.tokenRefreshSubscription.unsubscribe(); - try { - this.connectionStatus$.next(ConnectionStatus.Ended); - } catch (e) { - if (e === errorConversationEnded) - return; - throw(e); - } + this.ending = true; + this.connectionStatus$.next(ConnectionStatus.Ended); } getSessionId(): Observable {