|
15 | 15 | // specific language governing permissions and limitations |
16 | 16 | // under the License. |
17 | 17 |
|
| 18 | +import { createApp, h } from 'vue' |
18 | 19 | import { vueApp, vueProps } from './vue-app' |
19 | 20 | import router from './router' |
20 | 21 | import store from './store' |
@@ -60,20 +61,50 @@ vueApp.use(imagesUtilPlugin) |
60 | 61 | vueApp.use(extensions) |
61 | 62 | vueApp.use(directives) |
62 | 63 |
|
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 | + ) |
68 | 81 | } |
| 82 | + createApp(ErrorComponent).mount('#app') |
| 83 | +} |
69 | 84 |
|
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 |
71 | 100 |
|
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) |
78 | 110 | }) |
79 | | -}) |
|
0 commit comments