fix(#2443): catch fetch() network errors in bindAsyncForms doSubmit
Wrap the fetch() call in a try/catch so network errors (offline, DNS failure, CORS) surface via themedToast instead of becoming unhandled promise rejections. The asyncBtn finally() still restores the button either way — the catch just adds the missing operator feedback.
This commit is contained in:
parent
4b45c5cd3d
commit
bd7ae83860
1 changed files with 12 additions and 6 deletions
|
|
@ -85,12 +85,18 @@ export function bindAsyncForms(onSuccess) {
|
|||
// Errors are surfaced via themedToast; the caller does not re-throw
|
||||
// so asyncBtn's finally always runs (restoring the button).
|
||||
const doSubmit = async () => {
|
||||
const resp = await fetch(f.action, {
|
||||
method: f.method || 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: new URLSearchParams(new FormData(f)),
|
||||
redirect: 'manual',
|
||||
});
|
||||
let resp;
|
||||
try {
|
||||
resp = await fetch(f.action, {
|
||||
method: f.method || 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: new URLSearchParams(new FormData(f)),
|
||||
redirect: 'manual',
|
||||
});
|
||||
} catch (err) {
|
||||
themedToast('action failed: ' + err, { type: 'error' });
|
||||
return;
|
||||
}
|
||||
const ok = resp.ok || resp.type === 'opaqueredirect'
|
||||
|| (resp.status >= 200 && resp.status < 400);
|
||||
if (!ok) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue