fix(xo-web/vms/import): various fixes (#4118)

- dont swallow `importVm` error
- `importVms`: display errors on console
- dont redirect on failure
This commit is contained in:
Julien Fontanet 2019-04-04 10:10:45 +02:00 committed by Pierre Donias
parent f900a5ef4f
commit 95bcf0c080
2 changed files with 9 additions and 4 deletions

View File

@ -1388,8 +1388,9 @@ export const importVm = (file, type = 'xva', data = undefined, sr) => {
success(_('vmImportSuccess'), name) success(_('vmImportSuccess'), name)
return res.json().then(body => body.result) return res.json().then(body => body.result)
}) })
.catch(() => { .catch(err => {
error(_('vmImportFailed'), name) error(_('vmImportFailed'), name)
throw err
}) })
) )
} }
@ -1429,9 +1430,11 @@ export const importVdi = async vdi => {
export const importVms = (vms, sr) => export const importVms = (vms, sr) =>
Promise.all( Promise.all(
map(vms, ({ file, type, data }) => map(vms, ({ file, type, data }) =>
importVm(file, type, data, sr).catch(noop) importVm(file, type, data, sr).catch(error => {
) console.warn('importVms', file.name, error)
})
) )
).then(ids => ids.filter(_ => _ !== undefined))
import ExportVmModalBody from './export-vm-modal' // eslint-disable-line import/first import ExportVmModalBody from './export-vm-modal' // eslint-disable-line import/first
export const exportVm = vm => export const exportVm = vm =>

View File

@ -237,7 +237,9 @@ const parseFile = async (file, type, func) => {
} }
const getRedirectionUrl = vms => const getRedirectionUrl = vms =>
vms.length === 1 vms.length === 0
? undefined // no redirect
: vms.length === 1
? `/vms/${vms[0]}` ? `/vms/${vms[0]}`
: `/home?s=${encodeURIComponent(`id:|(${vms.join(' ')})`)}&t=VM` : `/home?s=${encodeURIComponent(`id:|(${vms.join(' ')})`)}&t=VM`