From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dcsapak@zita.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 7C37662F11
 for <pve-devel@lists.proxmox.com>; Tue, 14 Jul 2020 13:51:38 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 6C6FB2675E
 for <pve-devel@lists.proxmox.com>; Tue, 14 Jul 2020 13:51:08 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 9437C26755
 for <pve-devel@lists.proxmox.com>; Tue, 14 Jul 2020 13:51:07 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 510A0442CA
 for <pve-devel@lists.proxmox.com>; Tue, 14 Jul 2020 13:51:07 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Tue, 14 Jul 2020 13:51:05 +0200
Message-Id: <20200714115106.30195-4-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200714115106.30195-1-d.csapak@proxmox.com>
References: <20200714115106.30195-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery
 methods
 NO_DNS_FOR_FROM         0.379 Envelope sender has no MX or A DNS records
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_NONE                0.001 SPF: sender does not publish an SPF Record
Subject: [pve-devel] [PATCH xtermjs v2 3/4] ui: improve error message
 handling
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 14 Jul 2020 11:51:38 -0000

by splitting the msg and code, and only showing the existing parts
also actually read the msg/code from the event by giving it from
tryReconnect to stopTerminal

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
new in v2
 src/www/main.js | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/www/main.js b/src/www/main.js
index 4da40b0..55834eb 100644
--- a/src/www/main.js
+++ b/src/www/main.js
@@ -26,7 +26,7 @@ var nodename = getQueryParameter('node');
 var cmd = getQueryParameter('cmd');
 var cmdOpts = getQueryParameter('cmd-opts');
 
-function updateState(newState, msg) {
+function updateState(newState, msg, code) {
     var timeout, severity, message;
     switch (newState) {
 	case states.connecting:
@@ -77,8 +77,15 @@ function updateState(newState, msg) {
 	default:
 	    throw "unknown state";
     }
-    if (msg) {
-	message += " (" + msg + ")";
+    let msgArr = [];
+    if (msg !== undefined) {
+	msgArr.push(msg);
+    }
+    if (code !== undefined) {
+	msgArr.push(`Code: ${code}`);
+    }
+    if (msgArr.length > 0) {
+	message += ` (${msgArr.join(', ')})`;
     }
     state = newState;
     showMsg(message, timeout, severity);
@@ -279,11 +286,11 @@ function checkMigration() {
     });
 }
 
-function tryReconnect() {
+function tryReconnect(event) {
     var time_since_started = new Date() - starttime;
     var type = getQueryParameter('console');
     if (time_since_started < 5*1000 || type === 'shell' || type === 'cmd') { // 5 seconds
-	stopTerminal();
+	stopTerminal(event);
 	return;
     }
 
@@ -301,7 +308,7 @@ function stopTerminal(event) {
     clearEvents();
     clearInterval(ping);
     socket.close();
-    updateState(states.disconnected, event.msg + event.code);
+    updateState(states.disconnected, event.reason, event.code);
 }
 
 function errorTerminal(event) {
@@ -310,5 +317,5 @@ function errorTerminal(event) {
     clearInterval(ping);
     socket.close();
     term.dispose();
-    updateState(states.disconnected, event.msg + event.code);
+    updateState(states.disconnected, event.msg, event.code);
 }
-- 
2.20.1