Skip to content

Commit 1e387f2

Browse files
committed
index.html: handle/show errors in saveConfig()
1 parent 7dbf145 commit 1e387f2

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

static/index.html

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,29 @@ <h3 style="text-align: center; margin-bottom: 0.125rem">
212212
async function saveConfig() {
213213
const config = {};
214214
const ids = [{CONFIG_IDS}];
215-
ids.forEach((id) => (config[id] = getValue(id)));
216-
await fetch("/config", {
217-
method: "POST",
218-
headers: { "Content-Type": "application/json" },
219-
body: JSON.stringify(config),
215+
216+
ids.forEach((id) => {
217+
config[id] = getValue(id);
220218
});
221-
alert("Configuration saved!");
219+
220+
try {
221+
const response = await fetch("/config", {
222+
method: "POST",
223+
headers: { "Content-Type": "application/json" },
224+
body: JSON.stringify(config),
225+
});
226+
227+
if (!response.ok) {
228+
// Try to get error message from the response
229+
const errorText = await response.text();
230+
throw new Error(`Error ${response.status}: ${errorText}`);
231+
}
232+
233+
alert("✅ Configuration saved successfully!");
234+
} catch (error) {
235+
console.error("❌ Failed to save configuration:", error);
236+
alert(`❌ Failed to save configuration:\n${error.message}`);
237+
}
222238
}
223239

224240
loadConfig();

0 commit comments

Comments
 (0)