Skip to content

Commit 39835c0

Browse files
committed
Show error in UI if config.json is invalid
1 parent 0d58cb0 commit 39835c0

1 file changed

Lines changed: 44 additions & 13 deletions

File tree

ui/src/main.js

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
import { createApp, h } from 'vue'
1819
import { vueApp, vueProps } from './vue-app'
1920
import router from './router'
2021
import store from './store'
@@ -60,20 +61,50 @@ vueApp.use(imagesUtilPlugin)
6061
vueApp.use(extensions)
6162
vueApp.use(directives)
6263

63-
fetch('config.json?ts=' + Date.now()).then(response => response.json()).then(config => {
64-
vueProps.$config = config
65-
let basUrl = config.apiBase
66-
if (config.multipleServer) {
67-
basUrl = (config.servers[0].apiHost || '') + config.servers[0].apiBase
64+
const renderError = (err) => {
65+
console.error('Fatal error during app initialization:', err)
66+
const ErrorComponent = {
67+
render: () => h(
68+
'div',
69+
{ style: 'font-family: sans-serif; text-align: center; padding: 2rem;' },
70+
[
71+
h('h1', { style: 'color: #ff4d4f;' }, 'Application Error'),
72+
h('p', 'Could not start the application due to a configuration error.'),
73+
h('p', [
74+
'Please check that ',
75+
h('code', 'config.json'),
76+
' is present and correctly formatted.'
77+
]),
78+
h('p', { style: 'color: #888; font-size: 0.9em;' }, 'See the browser console for more details.')
79+
]
80+
)
6881
}
82+
createApp(ErrorComponent).mount('#app')
83+
}
6984

70-
vueProps.axios.defaults.baseURL = basUrl
85+
fetch('config.json?ts=' + Date.now())
86+
.then(response => {
87+
if (!response.ok) {
88+
throw new Error(`Failed to fetch config.json: ${response.status} ${response.statusText}`)
89+
}
90+
return response.json()
91+
})
92+
.then(config => {
93+
vueProps.$config = config
94+
let basUrl = config.apiBase
95+
if (config.multipleServer) {
96+
basUrl = (config.servers[0].apiHost || '') + config.servers[0].apiBase
97+
}
98+
99+
vueProps.axios.defaults.baseURL = basUrl
71100

72-
loadLanguageAsync().then(() => {
73-
vueApp.use(store)
74-
.use(router)
75-
.use(i18n)
76-
.use(bootstrap)
77-
.mount('#app')
101+
loadLanguageAsync().then(() => {
102+
vueApp.use(store)
103+
.use(router)
104+
.use(i18n)
105+
.use(bootstrap)
106+
.mount('#app')
107+
})
108+
}).catch(error => {
109+
renderError(error)
78110
})
79-
})

0 commit comments

Comments
 (0)