[pve-devel] [PATCH xtermjs v2 3/4] ui: improve error message handling
Dominik Csapak
d.csapak at proxmox.com
Tue Jul 14 13:51:05 CEST 2020
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 at 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
More information about the pve-devel
mailing list