refactor(client): update error handling to match adonis 5 validators

This commit is contained in:
Valentin Kaelin 2020-10-11 18:32:33 +02:00
parent 02360b4e92
commit 210a47f62d

View file

@ -115,7 +115,14 @@ export const actions = {
commit('BASIC_REQUEST') commit('BASIC_REQUEST')
try { try {
const resp = await axios(({ url: 'summoner/basic', data: { summoner, region: regionId }, method: 'POST' })) const resp = await axios(({ url: 'summoner/basic', data: { summoner, region: regionId }, method: 'POST' }))
if (resp.data) { if (!resp.data) {
dispatch('notification/add', {
type: 'error',
message: 'Summoner not found.'
}, { root: true })
return commit('SUMMONER_NOT_FOUND')
}
console.log(`---SUMMONER INFOS ${resp.data.account.name}---`) console.log(`---SUMMONER INFOS ${resp.data.account.name}---`)
console.log(resp.data) console.log(resp.data)
const infos = createBasicSummonerData(resp.data) const infos = createBasicSummonerData(resp.data)
@ -127,20 +134,16 @@ export const actions = {
icon: infos.account.profileIconId, icon: infos.account.profileIconId,
region, region,
}, { root: true }) }, { root: true })
} else { } catch (error) {
commit('SUMMONER_NOT_FOUND') if (error.response && error.response.status === 422) {
dispatch('notification/add', { dispatch('notification/add', {
type: 'error', type: 'error',
message: 'Summoner not found.' message: 'Summoner not found.'
}, { root: true }) }, { root: true })
console.log('Summoner not found - store')
} }
} catch (error) {
if (error.message !== 'Summoner changed') { if (error.message !== 'Summoner changed') {
commit('SUMMONER_NOT_FOUND') commit('SUMMONER_NOT_FOUND')
} }
console.log(error)
} }
}, },
championsNotLoaded({ commit }) { championsNotLoaded({ commit }) {