From: Jérôme Benoit Date: Mon, 19 Feb 2024 20:44:58 +0000 (+0100) Subject: fix(ui): fix initilisation logic X-Git-Tag: v1.2.38~74 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=5369437218a4bda8ac1adc1c2dcb33b1729f8f63;p=e-mobility-charging-stations-simulator.git fix(ui): fix initilisation logic Signed-off-by: Jérôme Benoit --- diff --git a/ui/web/src/main.ts b/ui/web/src/main.ts index d0c427bf..25f92db0 100644 --- a/ui/web/src/main.ts +++ b/ui/web/src/main.ts @@ -1,6 +1,6 @@ import { createApp } from 'vue' import ToastPlugin from 'vue-toast-notification' -import type { ConfigurationData, ResponsePayload } from './types' +import type { ConfigurationData, ResponsePayload } from '@/types' import { router } from '@/router' import { UIClient } from '@/composables' import App from '@/App.vue' @@ -28,7 +28,6 @@ const initializeApp = (config: ConfigurationData) => { .catch((error: Error) => { // TODO: add code for UI notifications or other error handling logic console.error('Error at fetching charging stations:', error) - throw error }) .finally(() => { app.use(router).use(ToastPlugin).mount('#app') @@ -37,15 +36,23 @@ const initializeApp = (config: ConfigurationData) => { } fetch('/config.json') - .then(response => response.json()) - .catch(error => { - console.error('Error at fetching app configuration:', error) - throw error - }) - .then(config => { - initializeApp(config) + .then(response => { + if (!response.ok) { + // TODO: add code for UI notifications or other error handling logic + console.error('Failed to fetch app configuration') + return + } + response + .json() + .then(config => { + initializeApp(config) + }) + .catch(error => { + // TODO: add code for UI notifications or other error handling logic + console.error('Error at app configuration JSON deserialization:', error) + }) }) .catch(error => { - console.error('Error at initializing app:', error) - throw error + // TODO: add code for UI notifications or other error handling logic + console.error('Error at fetching app configuration:', error) })