MT#60161 add an error message and stop the loading on network error

Change-Id: I620be6f60d27ea24fd5a25552be23f67336df1f8
mr13.0
Hugo Zigha 12 months ago
parent a0dfa84bc3
commit a66dff24a4

@ -25,6 +25,9 @@ import {
post, put, get, getList post, put, get, getList
} from 'src/api/common' } from 'src/api/common'
import _ from 'lodash' import _ from 'lodash'
import {
showGlobalError
} from 'src/helpers/ui'
const DEFAULT_RING_TIMEOUT = 60 const DEFAULT_RING_TIMEOUT = 60
const DEFAULT_PRIORITY = 0 const DEFAULT_PRIORITY = 0
@ -60,38 +63,43 @@ export async function loadMappingsFull ({ dispatch, commit, rootGetters }, subsc
} }
export async function createMapping ({ dispatch, commit, state, rootGetters }, payload) { export async function createMapping ({ dispatch, commit, state, rootGetters }, payload) {
dispatch('wait/start', WAIT_IDENTIFIER, { root: true }) try {
let type = payload.type dispatch('wait/start', WAIT_IDENTIFIER, { root: true })
if (payload.type === 'cfu' && state.mappings.cft && state.mappings.cft.length > 0) { let type = payload.type
type = 'cft' if (payload.type === 'cfu' && state.mappings.cft && state.mappings.cft.length > 0) {
} type = 'cft'
const subscriberId = (payload.subscriberId) ? (payload.subscriberId) : rootGetters['user/getSubscriberId']
const mappings = _.cloneDeep(state.mappings[type])
const destinationSetId = await post({
resource: 'cfdestinationsets',
body: {
name: 'csc-' + v4(),
subscriber_id: subscriberId,
destinations: [createDefaultDestination()]
} }
}) const subscriberId = (payload.subscriberId) ? (payload.subscriberId) : rootGetters['user/getSubscriberId']
mappings.push({ const mappings = _.cloneDeep(state.mappings[type])
destinationset_id: destinationSetId const destinationSet = await post({
}) resource: 'cfdestinationsets',
const res = await Promise.all([ body: {
patchReplaceFull({ name: 'csc-' + v4(),
resource: 'cfmappings', subscriber_id: subscriberId,
resourceId: subscriberId, destinations: [createDefaultDestination()]
fieldPath: type, }
value: mappings })
}), mappings.push({
cfLoadDestinationSets(rootGetters['user/getSubscriberId']) destinationset_id: destinationSet?.id
]) })
commit('dataSucceeded', { const res = await Promise.all([
mappings: res[0], patchReplaceFull({
destinationSets: res[1].items resource: 'cfmappings',
}) resourceId: subscriberId,
dispatch('wait/end', WAIT_IDENTIFIER, { root: true }) fieldPath: type,
value: mappings
}),
cfLoadDestinationSets(rootGetters['user/getSubscriberId'])
])
commit('dataSucceeded', {
mappings: res[0],
destinationSets: res[1].items
})
} catch (error) {
showGlobalError(error.message)
} finally {
dispatch('wait/end', WAIT_IDENTIFIER, { root: true })
}
} }
export async function deleteMapping ({ dispatch, commit, state, rootGetters }, payload) { export async function deleteMapping ({ dispatch, commit, state, rootGetters }, payload) {

Loading…
Cancel
Save