103103 </NcEmptyContent >
104104 </div >
105105 <div v-else >
106- <NcEmptyContent :name =" t('tables', 'Failed')" :description =" t('tables', 'Unable to import data') " />
106+ <NcEmptyContent :name =" t('tables', 'Failed')" :description =" errorMessage " />
107107 </div >
108108 </div >
109109
116116
117117<script >
118118import { NcDialog , NcButton , NcCheckboxRadioSwitch , NcEmptyContent , NcLoadingIcon } from ' @nextcloud/vue'
119- import { getFilePickerBuilder , FilePickerType , showError , showWarning } from ' @nextcloud/dialogs'
119+ import { getFilePickerBuilder , FilePickerType , showWarning } from ' @nextcloud/dialogs'
120120import RowFormWrapper from ' ../../shared/components/ncTable/partials/rowTypePartials/RowFormWrapper.vue'
121121import permissionsMixin from ' ../../shared/components/ncTable/mixins/permissionsMixin.js'
122122import IconFolder from ' vue-material-design-icons/Folder.vue'
@@ -184,6 +184,7 @@ export default {
184184 ' application/vnd.oasis.opendocument.spreadsheet' ,
185185 ],
186186 selectedUploadFile: null ,
187+ errorMessage: t (' tables' , ' Could not import data due to unknown errors.' ),
187188 }
188189 },
189190
@@ -289,23 +290,11 @@ export default {
289290 this .preview = res .data
290291 this .loading = false
291292 } else {
292- if (res .status === 401 ) {
293- console .debug (' error while importing' , res)
294- showError (t (' tables' , ' Could not import, not authorized. Are you logged in?' ))
295- } else if (res .status === 403 ) {
296- console .debug (' error while importing' , res)
297- showError (t (' tables' , ' Could not import, missing needed permission.' ))
298- } else if (res .status === 404 ) {
299- console .debug (' error while importing' , res)
300- showError (t (' tables' , ' Could not import, needed resources were not found.' ))
301- } else {
302- showError (t (' tables' , ' Could not import data due to unknown errors.' ))
303- console .debug (' error while importing' , res)
304- }
293+ this .handleResponse (res, null )
305294 this .importFailed = true
306295 }
307296 } catch (e) {
308- showError ( t (' tables' , ' Could not import data due to unknown errors.' ) )
297+ this . errorMessage = t (' tables' , ' Could not import data due to unknown errors.' )
309298 console .error (e)
310299 this .importFailed = true
311300 return false
@@ -328,23 +317,11 @@ export default {
328317 this .preview = res .data
329318 this .loading = false
330319 } else {
331- if (res .status === 401 ) {
332- console .debug (' error while importing' , res)
333- showError (t (' tables' , ' Could not import, not authorized. Are you logged in?' ))
334- } else if (res .status === 403 ) {
335- console .debug (' error while importing' , res)
336- showError (t (' tables' , ' Could not import, missing needed permission.' ))
337- } else if (res .status === 404 ) {
338- console .debug (' error while importing' , res)
339- showError (t (' tables' , ' Could not import, needed resources were not found.' ))
340- } else {
341- showError (t (' tables' , ' Could not import data due to unknown errors.' ))
342- console .debug (' error while importing' , res)
343- }
320+ this .handleResponse (res, null )
344321 this .importFailed = true
345322 }
346323 } catch (e) {
347- showError ( t (' tables' , ' Could not import data due to unknown errors.' ) )
324+ this . errorMessage = t (' tables' , ' Could not import data due to unknown errors.' )
348325 console .error (e)
349326 this .importFailed = true
350327 return false
@@ -406,22 +383,10 @@ export default {
406383 this .result = res .data
407384 } else {
408385 console .debug (' error while importing' , res)
409- showError ( t (' tables' , res .data ? .message || ' Could not import data due to unknown errors.' ) )
386+ this . errorMessage = t (' tables' , res .data ? .message || ' Could not import data due to unknown errors.' )
410387 }
411388 } catch (e) {
412- if (e .response ? .status === 401 ) {
413- console .debug (' error while importing' , e)
414- showError (t (' tables' , ' Could not import, not authorized. Are you logged in?' ))
415- } else if (e .response ? .status === 403 ) {
416- console .debug (' error while importing' , e)
417- showError (t (' tables' , ' Could not import, missing needed permission.' ))
418- } else if (e .response ? .status === 404 ) {
419- console .debug (' error while importing' , e)
420- showError (t (' tables' , ' Could not import, needed resources were not found.' ))
421- } else {
422- console .debug (' error while importing' , e)
423- showError (t (' tables' , e .response .data ? .message || ' Could not import data due to unknown errors.' ))
424- }
389+ this .handleResponse (e .response , e)
425390 }
426391 this .loading = false
427392 },
@@ -444,22 +409,10 @@ export default {
444409 this .result = res .data
445410 } else {
446411 console .debug (' error while importing' , res)
447- showError ( t (' tables' , res .data ? .message || ' Could not import data due to unknown errors.' ) )
412+ this . errorMessage = t (' tables' , res .data ? .message || ' Could not import data due to unknown errors.' )
448413 }
449414 } catch (e) {
450- if (e .response ? .status === 401 ) {
451- console .debug (' error while importing' , e)
452- showError (t (' tables' , ' Could not import, not authorized. Are you logged in?' ))
453- } else if (e .response ? .status === 403 ) {
454- console .debug (' error while importing' , e)
455- showError (t (' tables' , ' Could not import, missing needed permission.' ))
456- } else if (e .response ? .status === 404 ) {
457- console .debug (' error while importing' , e)
458- showError (t (' tables' , ' Could not import, needed resources were not found.' ))
459- } else {
460- console .debug (' error while importing' , e)
461- showError (t (' tables' , e .response ? .data ? .message || ' Could not import data due to unknown errors.' ))
462- }
415+ this .handleResponse (e .response , e)
463416 }
464417 this .loading = false
465418 },
@@ -505,6 +458,21 @@ export default {
505458 onUpdateColumnsConfig (event ) {
506459 this .columnsConfig = event
507460 },
461+ handleResponse (res , e ) {
462+ if (res? .status === 401 ) {
463+ console .debug (' error while importing' , e || res)
464+ this .errorMessage = t (' tables' , ' Could not import, not authorized. Are you logged in?' )
465+ } else if (res? .status === 403 ) {
466+ console .debug (' error while importing' , e || res)
467+ this .errorMessage = t (' tables' , ' Could not import, missing needed permission.' )
468+ } else if (res? .status === 404 ) {
469+ console .debug (' error while importing' , e || res)
470+ this .errorMessage = t (' tables' , ' Could not import, needed resources were not found.' )
471+ } else {
472+ console .debug (' error while importing' , e || res)
473+ this .errorMessage = t (' tables' , e? .response ? .data ? .message || ' Could not import data due to unknown errors.' )
474+ }
475+ },
508476 },
509477
510478}
0 commit comments