The URL I am trying to access is
http://mywebsite.com/[category that doesn't exist]
. Despite the code snippet provided below, I am unable to reach the catch block in asyncData.
async asyncData({ params, store }) {
try {
await store.dispatch('categories/GET_CATEGORIES')
await store.dispatch('products/GET_products', params.category)
} catch(e) {
console.log(e) // no output in the console
}
}
This is how the Vuex action looks like:
async GET_PRODUCTS({commit}, category) {
try {
let url
if (!category) {
url = 'some url'
} else {
url = 'some other url'
}
const response = await this.$axios.$get(url)
if (!response.length) throw new Error()
commit('some mutation', response.data)
} catch(e) {
console.log(e)
}
}
If an error is thrown, shouldn't it trigger the catch block in asyncData? My intention behind this is to utilize the router for redirecting to the home page upon encountering an error in the action logic.
I have come across limited information regarding directly integrating routing into Vuex (possibly not a good practice?). Nevertheless, asyncData provides access to the context
object which contains the router
.