diff --git a/packages/frontend/editor-ui/src/init.test.ts b/packages/frontend/editor-ui/src/init.test.ts index e17d2b417e..6a06acba4c 100644 --- a/packages/frontend/editor-ui/src/init.test.ts +++ b/packages/frontend/editor-ui/src/init.test.ts @@ -18,9 +18,10 @@ import { EnterpriseEditionFeature } from '@/constants'; import { useUIStore } from '@/stores/ui.store'; const showMessage = vi.fn(); +const showToast = vi.fn(); vi.mock('@/composables/useToast', () => ({ - useToast: () => ({ showMessage }), + useToast: () => ({ showMessage, showToast }), })); vi.mock('@/stores/users.store', () => ({ @@ -90,6 +91,23 @@ describe('Init', () => { expect(settingsStoreSpy).toHaveBeenCalledTimes(1); }); + it('should throw an error if settings initialization fails', async () => { + const error = new Error('Settings initialization failed'); + + vi.spyOn(settingsStore, 'initialize').mockImplementation(() => { + throw error; + }); + + await initializeCore(); + + expect(showToast).toHaveBeenCalledWith( + expect.objectContaining({ + title: 'Error connecting to n8n', + type: 'error', + }), + ); + }); + it('should initialize authentication hooks', async () => { const registerLoginHookSpy = vi.spyOn(usersStore, 'registerLoginHook'); const registerLogoutHookSpy = vi.spyOn(usersStore, 'registerLogoutHook'); diff --git a/packages/frontend/editor-ui/src/init.ts b/packages/frontend/editor-ui/src/init.ts index 336a8c22a7..ece0740165 100644 --- a/packages/frontend/editor-ui/src/init.ts +++ b/packages/frontend/editor-ui/src/init.ts @@ -43,13 +43,25 @@ export async function initializeCore() { const ssoStore = useSSOStore(); const uiStore = useUIStore(); + const toast = useToast(); + const i18n = useI18n(); + registerAuthenticationHooks(); /** * Initialize stores */ - await settingsStore.initialize(); + try { + await settingsStore.initialize(); + } catch (error) { + toast.showToast({ + title: i18n.baseText('startupError'), + message: i18n.baseText('startupError.message'), + type: 'error', + duration: 0, + }); + } ssoStore.initialize({ authenticationMethod: settingsStore.userManagement diff --git a/packages/frontend/editor-ui/src/stores/settings.store.ts b/packages/frontend/editor-ui/src/stores/settings.store.ts index b37e8b1435..bdc4518b7a 100644 --- a/packages/frontend/editor-ui/src/stores/settings.store.ts +++ b/packages/frontend/editor-ui/src/stores/settings.store.ts @@ -21,12 +21,9 @@ import type { IDataObject, WorkflowSettings } from 'n8n-workflow'; import { defineStore } from 'pinia'; import { useRootStore } from '@n8n/stores/useRootStore'; import { makeRestApiRequest } from '@n8n/rest-api-client'; -import { useToast } from '@/composables/useToast'; -import { useI18n } from '@n8n/i18n'; import { useLocalStorage } from '@vueuse/core'; export const useSettingsStore = defineStore(STORES.SETTINGS, () => { - const i18n = useI18n(); const initialized = ref(false); const settings = ref({} as FrontendSettings); const moduleSettings = ref({}); @@ -265,23 +262,11 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, () => { return; } - const { showToast } = useToast(); - try { - await getSettings(); + await getSettings(); - initialized.value = true; + initialized.value = true; - await getModuleSettings(); - } catch (e) { - showToast({ - title: i18n.baseText('startupError'), - message: i18n.baseText('startupError.message'), - type: 'error', - duration: 0, - }); - - throw e; - } + await getModuleSettings(); }; const stopShowingSetupPage = () => {