improve error handling for future error display,

fix styling with config disk actions

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2023-04-19 21:11:35 +00:00
parent 6d946f08f9
commit fcdfe020c6
2 changed files with 15 additions and 17 deletions

View File

@ -370,7 +370,7 @@ async function handleDiskAdd () {
options += `<option value="${element.storage}">${element.storage}</option>"`; options += `<option value="${element.storage}">${element.storage}</option>"`;
} }
}); });
let select = `<label for="storage-select">Storage</label><select name="storage-select" id="storage-select" required>${options}</select>`; let select = `<label for="storage-select">Storage</label><select class="w3-select w3-border" name="storage-select" id="storage-select" required>${options}</select>`;
dialog.formBody = ` dialog.formBody = `
<label for="device">${type === "qemu" ? "SATA" : "MP"}</label><input class="w3-input w3-border" name="device" id="device" type="number" min="0" max="${type === "qemu" ? "5" : "255"}" value="0" required></input> <label for="device">${type === "qemu" ? "SATA" : "MP"}</label><input class="w3-input w3-border" name="device" id="device" type="number" min="0" max="${type === "qemu" ? "5" : "255"}" value="0" required></input>
@ -420,12 +420,12 @@ async function handleCDAdd () {
storageOptions += `<option value="${element.storage}">${element.storage}</option>"`; storageOptions += `<option value="${element.storage}">${element.storage}</option>"`;
} }
}); });
let storageSelect = `<label for="storage-select">Storage</label><select name="storage-select" id="storage-select" required>${storageOptions}</select>`; let storageSelect = `<label for="storage-select">Storage</label><select class="w3-select w3-border" name="storage-select" id="storage-select" required>${storageOptions}</select>`;
dialog.formBody = ` dialog.formBody = `
<label for="device">IDE</label><input class="w3-input w3-border" name="device" id="device" type="number" min="0" max="3" required></input> <label for="device">IDE</label><input class="w3-input w3-border" name="device" id="device" type="number" min="0" max="3" required></input>
${storageSelect} ${storageSelect}
<label for="iso-select">Image</label><select name="iso-select" id="iso-select" required></select> <label for="iso-select">Image</label><select class="w3-select w3-border" name="iso-select" id="iso-select" required></select>
`; `;
dialog.shadowRoot.querySelector("#storage-select").selectedIndex = -1; dialog.shadowRoot.querySelector("#storage-select").selectedIndex = -1;

View File

@ -1,12 +1,5 @@
import {API} from "/vars.js"; import {API} from "/vars.js";
export class ResponseError extends Error {
constructor(message) {
super(message);
this.name = "ResponseError";
}
}
export class NetworkError extends Error { export class NetworkError extends Error {
constructor(message) { constructor(message) {
super(message); super(message);
@ -161,17 +154,22 @@ async function request (url, content) {
return response; return response;
}) })
.catch((error) => { .catch((error) => {
throw new NetworkError(error); return new NetworkError(error);
}); });
if(!response.ok){ if (response instanceof NetworkError) {
throw new ResponseError(response); return {status: 408, error: "network error"};
} }
else if(!response.ok){
let data = await response.json()
return {status: response.status, error: data.error};
}
else {
let data = await response.json(); let data = await response.json();
data.status = response.status; data.status = response.status;
return data; return data;
} }
}
export function goToPage (page, data={}, newwindow = false) { export function goToPage (page, data={}, newwindow = false) {
let url = new URL(`https://${window.location.host}/${page}`); let url = new URL(`https://${window.location.host}/${page}`);