fehlermeldungen gebaut
This commit is contained in:
+16
-16
@@ -1,23 +1,23 @@
|
||||
const API = "/resman/api"
|
||||
|
||||
const API="/resman/api";
|
||||
async function api(url, options = {}) {
|
||||
const res = await fetch(url, options)
|
||||
|
||||
async function api(url, options={}){
|
||||
let data
|
||||
|
||||
const res = await fetch(url, options);
|
||||
try {
|
||||
data = await res.json()
|
||||
} catch {
|
||||
data = {}
|
||||
}
|
||||
|
||||
if(!res.ok){
|
||||
if (!res.ok) {
|
||||
const msg = data.error || "Unbekannter Fehler"
|
||||
|
||||
let msg="API error";
|
||||
showError(msg)
|
||||
|
||||
try{
|
||||
const err=await res.json();
|
||||
msg=err.error || msg;
|
||||
}catch(e){}
|
||||
|
||||
alert("Fehler: "+msg);
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
return res.json();
|
||||
}
|
||||
throw new Error(msg)
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
@@ -77,3 +77,25 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
function showError(msg) {
|
||||
|
||||
const div = document.createElement("div")
|
||||
|
||||
div.innerText = msg
|
||||
|
||||
div.style.position = "fixed"
|
||||
div.style.bottom = "20px"
|
||||
div.style.right = "20px"
|
||||
div.style.background = "#dc2626"
|
||||
div.style.color = "white"
|
||||
div.style.padding = "10px 15px"
|
||||
div.style.borderRadius = "6px"
|
||||
div.style.zIndex = 9999
|
||||
|
||||
document.body.appendChild(div)
|
||||
|
||||
setTimeout(() => {
|
||||
div.remove()
|
||||
}, 3000)
|
||||
}
|
||||
@@ -204,7 +204,9 @@ window.saveIP = async function(){
|
||||
return
|
||||
}
|
||||
}
|
||||
}catch(e){}
|
||||
}catch(e){
|
||||
console.log("Save IP Fehler:", e)
|
||||
}
|
||||
|
||||
await api(API + "/resources/" + resourceId + "/ips", {
|
||||
method: "POST",
|
||||
|
||||
Reference in New Issue
Block a user