From 3b3eb26693617b910e26d359028489c3cc3a18a5 Mon Sep 17 00:00:00 2001 From: Alex Sorafumo Date: Thu, 29 Oct 2026 13:19:51 +1100 Subject: [PATCH] fix(settings): stop a failed user settings load from raising an unhandled error SettingsService.init() runs from the constructor and nothing awaits it. When the user settings request failed (Safari reports "TypeError: Load failed" when the page navigates away mid-request), the rejection was unhandled and went to Sentry. Catch it, log a warning and keep the default settings. Fixes BACKOFFICE-4T Co-Authored-By: Claude Opus 5.5 --- src/app/common/settings.service.ts | 14 +++++++++++++- src/tests/common/settings.spec.ts | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/app/common/settings.service.ts b/src/app/common/settings.service.ts index cdc940adb..76d48a066 100644 --- a/src/app/common/settings.service.ts +++ b/src/app/common/settings.service.ts @@ -116,7 +116,19 @@ export class SettingsService extends AsyncHandler { (user) => !!user, ).catch(() => null); if (!user) return; - const data = await showMetadata(user.id, 'settings'); + // Nothing awaits init(), so a failed load must not reject. + // The defaults stay in use until the next page load. + const data = await showMetadata(user.id, 'settings').catch((err) => { + log( + 'Settings', + 'Failed to load user settings', + [err as object], + 'warn', + true, + ); + return null; + }); + if (!data) return; this._user_settings.set((data.details || {}) as HashMap); this._initDarkMode(); this._applyTheme(); diff --git a/src/tests/common/settings.spec.ts b/src/tests/common/settings.spec.ts index 03b4a9b2d..639b8c20d 100644 --- a/src/tests/common/settings.spec.ts +++ b/src/tests/common/settings.spec.ts @@ -41,6 +41,9 @@ vi.mock('../../app/common/general', () => ({ log: vi.fn(), })); +import { showMetadata } from '@placeos/ts-client'; + +import { log } from '../../app/common/general'; import { DEFAULT_SETTINGS } from '../../app/common/settings'; import { SettingsService } from '../../app/common/settings.service'; @@ -102,6 +105,20 @@ describe('SettingsService', () => { expect(service.app_name).toBeDefined(); expect(typeof service.app_name).toBe('string'); }); + + it('should not reject when user settings fail to load', async () => { + vi.mocked(showMetadata).mockRejectedValueOnce( + new TypeError('Load failed'), + ); + await expect(service.init()).resolves.toBeUndefined(); + expect(log).toHaveBeenCalledWith( + 'Settings', + 'Failed to load user settings', + [expect.any(TypeError)], + 'warn', + true, + ); + }); }); describe('title getter/setter', () => {