fehlermeldungen gebaut

This commit is contained in:
ecki
2026-04-05 18:15:53 +02:00
parent 80b96319ee
commit 8aa85d47a7
8 changed files with 76 additions and 35 deletions
+16 -16
View File
@@ -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
}