From 23f3153294e2276c82a986bee587b772b76c0d91 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Tue, 17 Jan 2023 12:41:52 -0800 Subject: [PATCH] set instance to original if request returns an error Signed-off-by: Arthur Lu --- scripts/elements.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/elements.js b/scripts/elements.js index e53ad7e..bde299f 100644 --- a/scripts/elements.js +++ b/scripts/elements.js @@ -76,7 +76,24 @@ class Instance extends HTMLElement { let configButton = this.shadowElement.querySelector("#configure-btn"); configButton.src = "images/actions/config-inactive.svg"; - let task = await request(`/nodes/${this.node}/${this.type}/${this.vmid}/status/${targetAction}`, "POST", {node: this.node, vmid: this.vmid}); + try { + let task = await request(`/nodes/${this.node}/${this.type}/${this.vmid}/status/${targetAction}`, "POST", {node: this.node, vmid: this.vmid}); + } + catch { + typeImg.src = `images/instances/${this.type}/${this.status}.svg`; + typeImg.alt = `${this.status} instance`; + + powerButton.src = this.status === "running" ? "images/actions/stop.svg" : "images/actions/start.svg"; + powerButton.alt = this.status === "running" ? "shutdown instance" : "start instance"; + + configButton.src = this.status === "running" ? "images/actions/config-inactive.svg" : "images/actions/config-active.svg"; + + this.actionLock = false; + + console.error(`attempted to ${targetAction} ${this.vmid} but process returned stopped:${taskStatus.data.exitstatus}`); + + return; + } while (true) { let taskStatus = await request(`/nodes/${this.node}/tasks/${task.data}/status`);