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', () => {