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>"`;
}
});
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 = `
<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>"`;
}
});
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 = `
<label for="device">IDE</label><input class="w3-input w3-border" name="device" id="device" type="number" min="0" max="3" required></input>
${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;

View File

@ -1,12 +1,5 @@
import {API} from "/vars.js";
export class ResponseError extends Error {
constructor(message) {
super(message);
this.name = "ResponseError";
}
}
export class NetworkError extends Error {
constructor(message) {
super(message);
@ -161,16 +154,21 @@ async function request (url, content) {
return response;
})
.catch((error) => {
throw new NetworkError(error);
return new NetworkError(error);
});
if(!response.ok){
throw new ResponseError(response);
if (response instanceof NetworkError) {
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();
data.status = response.status;
return data;
}
}
export function goToPage (page, data={}, newwindow = false) {