fix(#2443): address asyncBtn review notes
- asyncBtn now returns fn().finally(...) so callers can await/chain it - Move re-fetch calls inside try/catch in core.js and permissions.js so network errors from fetchAndRenderStalePerms / fetchAndRender* are caught instead of escaping as unhandled rejections - clearStaleAgent returns the asyncBtn promise so the function is properly awaitable when a button is present - Update asyncBtn doc comment to reflect the return-value contract
This commit is contained in:
parent
bd7ae83860
commit
1acc271108
3 changed files with 11 additions and 10 deletions
|
|
@ -115,12 +115,11 @@ function renderStalePerms(root, ghosts) {
|
|||
errP.hidden = false;
|
||||
return;
|
||||
}
|
||||
await fetchAndRenderStalePerms();
|
||||
} catch (err) {
|
||||
errP.textContent = 'failed to clear perms for ' + name + ': ' + err;
|
||||
errP.hidden = false;
|
||||
return;
|
||||
}
|
||||
await fetchAndRenderStalePerms();
|
||||
}));
|
||||
li.append(btn);
|
||||
ul.append(li);
|
||||
|
|
|
|||
|
|
@ -337,17 +337,17 @@ async function clearStaleAgent(name, sectionRoot) {
|
|||
setSaveNote('failed to remove ' + name + ': ' + text, true);
|
||||
return;
|
||||
}
|
||||
// Re-fetch both sections so the stale row disappears.
|
||||
await Promise.all([fetchAndRenderCapabilities(), fetchAndRenderToolGroups()]);
|
||||
} catch (err) {
|
||||
setSaveNote('failed to remove ' + name + ': ' + err, true);
|
||||
return;
|
||||
}
|
||||
// Re-fetch both sections so the stale row disappears.
|
||||
await Promise.all([fetchAndRenderCapabilities(), fetchAndRenderToolGroups()]);
|
||||
};
|
||||
// asyncBtn guards double-submit; fall through without guard when there
|
||||
// is no button (e.g. called programmatically without a DOM context).
|
||||
if (btn) asyncBtn(btn, doDelete);
|
||||
else await doDelete();
|
||||
// Return the promise so callers can await clearStaleAgent() if needed.
|
||||
if (btn) return asyncBtn(btn, doDelete);
|
||||
await doDelete();
|
||||
}
|
||||
|
||||
function clearSaveStatus() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue