From 8c88abecb931cc4ebfa5bb55e4b406db30e46ef8 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 18 Apr 2026 09:14:24 +0000 Subject: fix(settings): catch errors in settings sync fetch chains The settings store's subscribe callback kicked off a fetch chain to pull/push settings with no .catch() on either promise chain. A network failure or non-ok PUT from /api/configuration would surface as an unhandled promise rejection. Attach a .catch() that logs a descriptive error on both the pull and push chains so sync failures become observable without crashing the page. --- src/stores/settings.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/stores/settings.ts b/src/stores/settings.ts index cd0f306d..b3706b95 100644 --- a/src/stores/settings.ts +++ b/src/stores/settings.ts @@ -195,8 +195,8 @@ settings.subscribe((value) => { if (!browser) return; if (value.settingsSync && get(settingsSyncPulled) === true) { - fetch(root(`/api/configuration?id=${get(identity).id}`)).then( - (response) => { + fetch(root(`/api/configuration?id=${get(identity).id}`)) + .then((response) => { if (response.ok) response.json().then((data) => { const isEqualsJson = ( @@ -220,17 +220,21 @@ settings.subscribe((value) => { fetch(root(`/api/configuration`), { method: "PUT", body: JSON.stringify(value), - }).then((response) => { - if (response.ok) console.log("Pushed local configuration"); - - settingsSyncTimes.update((times) => ({ - ...times, - lastPush: new Date(), - })); - }); + }) + .then((response) => { + if (response.ok) console.log("Pushed local configuration"); + + settingsSyncTimes.update((times) => ({ + ...times, + lastPush: new Date(), + })); + }) + .catch((error) => + console.error("Settings sync push failed", error), + ); }); - }, - ); + }) + .catch((error) => console.error("Settings sync pull failed", error)); } }); -- cgit v1.2.3