From 210a47f62d871be8e58a3562d5a06988735c91f0 Mon Sep 17 00:00:00 2001 From: Valentin Kaelin Date: Sun, 11 Oct 2020 18:32:33 +0200 Subject: [PATCH] refactor(client): update error handling to match adonis 5 validators --- client/src/store/modules/summoner.js | 37 +++++++++++++++------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/client/src/store/modules/summoner.js b/client/src/store/modules/summoner.js index 306d2f7..3be5f4a 100644 --- a/client/src/store/modules/summoner.js +++ b/client/src/store/modules/summoner.js @@ -115,32 +115,35 @@ export const actions = { commit('BASIC_REQUEST') try { const resp = await axios(({ url: 'summoner/basic', data: { summoner, region: regionId }, method: 'POST' })) - if (resp.data) { - console.log(`---SUMMONER INFOS ${resp.data.account.name}---`) - console.log(resp.data) - const infos = createBasicSummonerData(resp.data) - commit('SUMMONER_FOUND', infos) - - // Add summoner to recent searches - dispatch('settings/addRecentSearch', { - name: infos.account.name, - icon: infos.account.profileIconId, - region, - }, { root: true }) - } else { - commit('SUMMONER_NOT_FOUND') - + if (!resp.data) { dispatch('notification/add', { type: 'error', message: 'Summoner not found.' }, { root: true }) - console.log('Summoner not found - store') + return commit('SUMMONER_NOT_FOUND') } + + console.log(`---SUMMONER INFOS ${resp.data.account.name}---`) + console.log(resp.data) + const infos = createBasicSummonerData(resp.data) + commit('SUMMONER_FOUND', infos) + + // Add summoner to recent searches + dispatch('settings/addRecentSearch', { + name: infos.account.name, + icon: infos.account.profileIconId, + region, + }, { root: true }) } catch (error) { + if (error.response && error.response.status === 422) { + dispatch('notification/add', { + type: 'error', + message: 'Summoner not found.' + }, { root: true }) + } if (error.message !== 'Summoner changed') { commit('SUMMONER_NOT_FOUND') } - console.log(error) } }, championsNotLoaded({ commit }) {