Skip to content

Commit 106757e

Browse files
committed
show error page if config.json is not valid
1 parent 0d58cb0 commit 106757e

File tree

1 file changed

+44
-13
lines changed

1 file changed

+44
-13
lines changed

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('h2', { style: 'color: #ff4d4f;' }, 'We\'re experiencing a problem'),
72+
h('p', 'The application could not be loaded due to a configuration issue. Please try again later.'),
73+
h('details', { style: 'margin-top: 20px;' }, [
74+
h('summary', { style: 'cursor: pointer;' }, 'Technical details'),
75+
h('pre', {
76+
style: 'text-align: left; display: inline-block; margin-top: 10px;'
77+
}, 'Missing or malformed config.json. Please ensure the file is present, accessible, and contains valid JSON. Check the browser console for more information.')
78+
])
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 baseUrl = config.apiBase
95+
if (config.multipleServer) {
96+
baseUrl = (config.servers[0].apiHost || '') + config.servers[0].apiBase
97+
}
98+
99+
vueProps.axios.defaults.baseURL = baseUrl
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)