fix(web): show the action script's error in the file-manager widgets (#574)

A failing plugin action returns a 400 whose JSON body carries the
script's own message, but both file-manager widgets threw it away:
plugin-file-manager's toggle always said "Toggle failed", and
json-file-manager's request helper threw "Server error 400" before
reading the body. That hid of-the-day's "Category ... not found in
config", which is why its toggles looked broken for no reason.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Chuck
2026-09-14 13:26:46 -04:00
committed by GitHub
co-authored by Claude Opus 5
parent 11bf39cd66
commit a6b3384032
2 changed files with 10 additions and 3 deletions
@@ -440,8 +440,13 @@
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body)
});
if (!r.ok) throw new Error('Server error ' + r.status);
const ct = r.headers.get('content-type') || '';
if (!r.ok) {
// A failing action script comes back as a 400 whose JSON body
// carries the script's own message; surface it, not the status.
const data = ct.includes('application/json') ? await r.json().catch(() => null) : null;
throw new Error(data?.message || 'Server error ' + r.status);
}
if (!ct.includes('application/json')) {
const txt = await r.text();
throw new Error('Unexpected response: ' + txt.slice(0, 120));
@@ -729,12 +729,14 @@
window._pfmToggle = async function (fieldId, categoryName, enabled) {
const st = getState(fieldId);
const result = await callAction(st.pluginId, st.actions.toggle, { category_name: categoryName, enabled })
.catch(() => ({ status: 'error' }));
.catch(() => ({ status: 'error', message: 'Network error' }));
if (result.status === 'success') {
notify(enabled ? `${categoryName} enabled` : `${categoryName} disabled`, 'success');
await loadFiles(fieldId);
} else {
notify('Toggle failed', 'error');
// The action endpoint relays the script's own message on failure;
// without it every error reads as a bare "Toggle failed".
notify(result.message ? `Toggle failed: ${result.message}` : 'Toggle failed', 'error');
await loadFiles(fieldId); // revert UI
}
};