| 2765 | } |
| 2766 | |
| 2767 | protected handleConnectionClosed() { |
| 2768 | // Check whether this is a normal shutdown in progress or the client stopped normally. |
| 2769 | if (this.state === ClientState.Stopping || this.state === ClientState.Stopped) { |
| 2770 | return; |
| 2771 | } |
| 2772 | try { |
| 2773 | if (this._resolvedConnection) { |
| 2774 | this._resolvedConnection.dispose(); |
| 2775 | } |
| 2776 | } catch (error) { |
| 2777 | // Disposing a connection could fail if error cases. |
| 2778 | } |
| 2779 | let action = CloseAction.DoNotRestart; |
| 2780 | try { |
| 2781 | action = this._clientOptions.errorHandler!.closed(); |
| 2782 | } catch (error) { |
| 2783 | // Ignore errors coming from the error handler. |
| 2784 | } |
| 2785 | this._connectionPromise = undefined; |
| 2786 | this._resolvedConnection = undefined; |
| 2787 | if (action === CloseAction.DoNotRestart) { |
| 2788 | this.error('Connection to server got closed. Server will not be restarted.'); |
| 2789 | this.state = ClientState.Stopped; |
| 2790 | this.cleanUp(false); |
| 2791 | } else if (action === CloseAction.Restart) { |
| 2792 | this.info('Connection to server got closed. Server will restart.'); |
| 2793 | this.cleanUp(true); |
| 2794 | this.state = ClientState.Initial; |
| 2795 | this.start(); |
| 2796 | } |
| 2797 | } |
| 2798 | |
| 2799 | private handleConnectionError(error: Error, message: Message, count: number) { |
| 2800 | let action = this._clientOptions.errorHandler!.error(error, message, count); |