From 5369437218a4bda8ac1adc1c2dcb33b1729f8f63 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 19 Feb 2024 21:44:58 +0100 Subject: [PATCH] fix(ui): fix initilisation logic MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- ui/web/src/main.ts | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) 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) }) -- 2.34.1