Currently using Nuxt 2 with some customizations.
All application state management is handled within Vuex modules, totaling 32 for this complex app. When fetching data, a call to fetch
is made from the view, triggering a mapped Vuex action that wraps the Axios call in a try...catch
block.
A simplified version of an action looks like this:
async fetchVotes ({ commit }) {
try {
const response = await this.$secured.get('exampleapi.com/votes')
const merged = jsonApiMerge(response.data.included, response.data.data)
// further processing
commit(SET_VOTES_LIST, merged)
} catch (err) {
console.log(err)
}
}
Overall, everything functions as intended.
However, I'm facing an issue where I am unable to redirect to the error
layout. In the catch
block, I would like to execute something like
this.$error({ statusCode: err.code, message: err.message })
, but there doesn't appear to be any accessible methods or properties on this
for this purpose.
What would be the correct approach to handle this scenario?