55<template >
66 <div class =" row" >
77 <div v-if =" loading" class =" icon-loading" />
8- <div v-if =" !loading && context" >
8+
9+ <div v-else-if =" activeContext" >
910 <div class =" content context" >
1011 <div class =" row first-row" >
1112 <h1 class =" context__title" data-cy =" context-title" >
3233 </div >
3334 </div >
3435 </div >
35-
36- <MainModals />
3736 </div >
37+
38+ <ErrorMessage v-else-if =" errorMessage " :message =" errorMessage " />
39+
40+ <MainModals />
3841 </div >
3942</template >
4043
@@ -50,11 +53,14 @@ import exportTableMixin from '../shared/components/ncTable/mixins/exportTableMix
5053import svgHelper from ' ../shared/components/ncIconPicker/mixins/svgHelper.js'
5154import { useTablesStore } from ' ../store/store.js'
5255import { useDataStore } from ' ../store/data.js'
56+ import ErrorMessage from ' ../modules/main/partials/ErrorMessage.vue'
57+ import displayError , { getNotFoundError , getGenericLoadError } from ' ../shared/utils/displayError.js'
5358
5459export default {
5560 components: {
5661 MainModals,
5762 NcIconSvgWrapper,
63+ ErrorMessage,
5864 TableWrapper,
5965 CustomView,
6066 },
@@ -73,6 +79,7 @@ export default {
7379 viewSetting: {},
7480 context: null ,
7581 contextResources: [],
82+ errorMessage: null ,
7683 }
7784 },
7885
@@ -114,14 +121,12 @@ export default {
114121 },
115122
116123 watch: {
117- // Watch for changes to active context to make page reactive
118124 async activeContext () {
119- if (this .activeContextId && ! this .activeContext ) {
120- // context does not exists, go to startpage
121- this .$router .push (' /' ).catch (err => err)
122- } else {
123- await this .reload ()
125+ if (this .errorMessage ) {
126+ // Already showing an error, don't redirect
127+ return
124128 }
129+ await this .reload ()
125130 },
126131 ' context.iconName' : {
127132 async handler (value ) {
@@ -146,49 +151,71 @@ export default {
146151 return
147152 }
148153 this .loading = true
149- this .icon = await this .getContextIcon (this .activeContext .iconName )
150154 this .contextResources = []
151- await this .loadContext ({ id: this .activeContextId })
152- const index = this .contexts .findIndex (c => parseInt (c .id ) === parseInt (this .activeContextId ))
153- this .context = this .contexts [index]
154155
155- if (this .context && this .context .nodes ) {
156- for (const [, node ] of Object .entries (this .context .nodes )) {
157- const nodeType = parseInt (node .node_type )
158- if (nodeType === NODE_TYPE_TABLE ) {
159- const table = this .tables .find (table => table .id === node .node_id )
160- if (table) {
161- await this .loadColumnsFromBE ({
162- view: null ,
163- tableId: table .id ,
164- })
165- await this .loadRowsFromBE ({
166- viewId: null ,
167- tableId: table .id ,
168- })
169- table .key = (table .id ).toString ()
170- table .isView = false
171- this .contextResources .push (table)
172- }
156+ try {
157+ await this .loadContext ({ id: this .activeContextId })
158+ const index = this .contexts .findIndex (c => parseInt (c .id ) === parseInt (this .activeContextId ))
159+ this .context = this .contexts [index]
160+
161+ if (! this .context ) {
162+ this .errorMessage = t (' tables' , ' This application could not be found' )
163+ return
164+ }
173165
174- } else if (nodeType === NODE_TYPE_VIEW ) {
175- const view = this .views .find (view => view .id === node .node_id )
176- if (view) {
177- await this .loadColumnsFromBE ({
178- view,
179- })
180- await this .loadRowsFromBE ({
181- viewId: view .id ,
182- tableId: view .tableId ,
183- })
184- view .key = ' view-' + (view .id ).toString ()
185- view .isView = true
186- this .contextResources .push (view)
166+ this .icon = await this .getContextIcon (this .activeContext .iconName )
167+
168+ if (this .context && this .context .nodes ) {
169+ for (const [, node ] of Object .entries (this .context .nodes )) {
170+ try {
171+ const nodeType = parseInt (node .node_type )
172+ if (nodeType === NODE_TYPE_TABLE ) {
173+ const table = this .tables .find (table => table .id === node .node_id )
174+ if (table) {
175+ await this .loadColumnsFromBE ({
176+ view: null ,
177+ tableId: table .id ,
178+ })
179+ await this .loadRowsFromBE ({
180+ viewId: null ,
181+ tableId: table .id ,
182+ })
183+ table .key = (table .id ).toString ()
184+ table .isView = false
185+ this .contextResources .push (table)
186+ }
187+
188+ } else if (nodeType === NODE_TYPE_VIEW ) {
189+ const view = this .views .find (view => view .id === node .node_id )
190+ if (view) {
191+ await this .loadColumnsFromBE ({
192+ view,
193+ })
194+ await this .loadRowsFromBE ({
195+ viewId: view .id ,
196+ tableId: view .tableId ,
197+ })
198+ view .key = ' view-' + (view .id ).toString ()
199+ view .isView = true
200+ this .contextResources .push (view)
201+ }
202+ }
203+ } catch (err) {
204+ console .error (` Failed to load resource ${ node .node_id } :` , err)
205+ this .errorMessage = t (' tables' , ' Some resources in this application could not be loaded' )
187206 }
188207 }
189208 }
209+ } catch (e) {
210+ if (e .message === ' NOT_FOUND' ) {
211+ this .errorMessage = getNotFoundError (' application' )
212+ } else {
213+ this .errorMessage = getGenericLoadError (' application' )
214+ displayError (e, this .errorMessage )
215+ }
216+ } finally {
217+ this .loading = false
190218 }
191- this .loading = false
192219 },
193220 createColumn (isView , element ) {
194221 emit (' tables:column:create' , { isView, element })
0 commit comments