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
View File
+5
View File
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"semi": false,
"trailingComma": "none"
}
+12 -8
View File
@@ -35,24 +35,28 @@ exports.remove = async (req, res) => {
}; };
exports.update = async (req, res) => { exports.update = async (req, res) => {
try { try {
const { ip, type, comment } = req.body
const {ip, type, comment} = req.body; if (!ip) {
return res.status(400).json({ error: "IP darf nicht leer sein" })
}
await db.query( await db.query(
"UPDATE resource_ips SET ip=?, type=?, comment=? WHERE id=?", "UPDATE resource_ips SET ip=?, type=?, comment=? WHERE id=?",
[ip, type, comment, req.params.id] [ip, type, comment, req.params.id]
); )
res.json({success:true}); res.json({ success: true })
} catch (e) { } catch (e) {
console.error("UPDATE IP error:", e)
console.error("UPDATE IP error:", e); res.status(500).json({
res.status(500).json({error:"DB error"}); error: "IP konnte nicht gespeichert werden"
})
}
} }
};
+14 -14
View File
@@ -1,23 +1,23 @@
const API = "/resman/api"
const API="/resman/api";
async function api(url, options = {}) { async function api(url, options = {}) {
const res = await fetch(url, options)
const res = await fetch(url, options); let data
if(!res.ok){
let msg="API error";
try { try {
const err=await res.json(); data = await res.json()
msg=err.error || msg; } catch {
}catch(e){} data = {}
alert("Fehler: "+msg);
throw new Error(msg);
} }
return res.json(); if (!res.ok) {
const msg = data.error || "Unbekannter Fehler"
showError(msg)
throw new Error(msg)
} }
return data
}
+22
View File
@@ -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)
}
+3 -1
View File
@@ -204,7 +204,9 @@ window.saveIP = async function(){
return return
} }
} }
}catch(e){} }catch(e){
console.log("Save IP Fehler:", e)
}
await api(API + "/resources/" + resourceId + "/ips", { await api(API + "/resources/" + resourceId + "/ips", {
method: "POST", method: "POST",
+8
View File
@@ -60,3 +60,11 @@ error: err.message || "Internal Server Error"
app.listen(3000, () => { app.listen(3000, () => {
console.log("ResMan running on port 3000"); console.log("ResMan running on port 3000");
}); });
app.use((err, req, res, next) => {
console.error("GLOBAL ERROR:", err)
res.status(500).json({
error: "Interner Serverfehler"
})
})
+1 -1
View File
@@ -1,4 +1,4 @@
version: "3.9" # version: "3.9"
services: services:
db: db: