]> git.proxmox.com Git - pve-xtermjs.git/commitdiff
ui: improve error message handling
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 21 Jul 2020 09:00:47 +0000 (11:00 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 23 Jul 2020 10:13:31 +0000 (12:13 +0200)
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>
src/www/main.js

index 4da40b09305dd51e9990271110cb7a0796db363b..bb71812b3ada042993bc5fc5ea2b8c6aaadd11c3 100644 (file)
@@ -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";
     }
+    let msgArr = [];
     if (msg) {
-       message += " (" + msg + ")";
+       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);
 }