add bottom padding to main,

improve error handling with request function
This commit is contained in:
Arthur Lu 2023-10-18 19:33:58 +00:00
parent 54ecfaf782
commit 4e4b63f63a
5 changed files with 31 additions and 23 deletions

View File

@ -53,7 +53,7 @@
</nav>
</header>
<main>
<section class="w3-container">
<section>
<h2>Account</h2>
<div class="w3-card w3-padding">
<h3>Account Details</h3>

View File

@ -26,7 +26,7 @@
</nav>
</header>
<main>
<section class="w3-container">
<section>
<h2 id="name"><a href="index.html">Instances</a> / %{vmname}</h2>
<form>
<fieldset class="w3-card w3-padding">

View File

@ -43,6 +43,10 @@ main, dialog {
color: var(--main-text-color);
}
main {
padding: 0 16px 16px 16px;
}
.w3-card {
background-color: var(--main-card-bg-color);
box-shadow: var(--main-card-box-shadow);

View File

@ -56,7 +56,7 @@
</nav>
</header>
<main>
<section class="w3-container">
<section>
<h2>Instances</h2>
<div class="w3-card w3-padding">
<div class="flex row nowrap" style="margin-top: 1em; justify-content: space-between;">

View File

@ -207,27 +207,31 @@ export async function requestAPI (path, method, body = null) {
}
async function request (url, content) {
const response = await fetch(url, content);
const contentType = response.headers.get("Content-Type");
let data = null;
if (contentType.includes("application/json")) {
data = await response.json();
data.status = response.status;
try {
const response = await fetch(url, content);
const contentType = response.headers.get("Content-Type");
let data = null;
if (contentType.includes("application/json")) {
data = await response.json();
data.status = response.status;
}
else if (contentType.includes("text/html")) {
data = { data: await response.text() };
data.status = response.status;
}
else {
data = response;
}
if (!response.ok) {
return { status: response.status, error: data ? data.error : response.status };
}
else {
data.status = response.status;
return data || response;
}
}
else if (contentType.includes("text/html")) {
data = { data: await response.text() };
data.status = response.status;
}
else {
data = response;
}
if (!response.ok) {
return { status: response.status, error: data ? data.error : response.status };
}
else {
data.status = response.status;
return data || response;
catch (error) {
return {status: 400, error: error};
}
}