A
A
Alexander Florenko2019-08-31 23:49:04
Vue.js
Alexander Florenko, 2019-08-31 23:49:04

How to handle vue + ssr 404 errors?

Hello.
There is an application on vue + ssr. There is a page, for example, with a product.
I can't figure out what to do if the product is not in the database.
I took the vue + ssr config here
And so. There is a component product.vue
Actions are called in asyncData

async asyncData({store, route}) {
  await store.dispatch('GET_PRODUCT', route.params.id);
},

The actions itself looks like this
GET_PRODUCT: async ({ commit }, id) => {
    try {
        const RES = await productApi.GET_PRODUCT(id);
        await commit('SET_PRODUCT', RES.data);
    } catch (e) {
        console.log(e.response);
    }
},

If the product is not in the database, the api returns a 404 error to me.
And response Where can I check what comes in the response, and if I receive a 404 error, do it ? In actions and asyncData I can't access{ error: '404 error' }
$router.push({name: '404'})
$router

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question