Static GitHub Issues

[2247] How to handle errors with Dynamic pages and when asyncData hit 404 API response?

prev: Cannot read property 'status' of undefined
next: Problem with jquery plugins and server side rendering

Hi there. I am trying to make error handling with custom error page, but this is not working in my case.

I have dynamic Page Components

asyncData ({ app, params, store }) {
    return app.$axios.get(`${process.env.baseUrl}/articles/${params.section}`)
      .then((res) => {
        store.commit('setArticles', res.data)
        return { error: false }
      })
      .catch((err) => {
        return { error: err.response.status }
      })
  }

Folder structure like this

pages
  _section
  index.vue

When I hit non existed section route I want to show error page. I have an error returned from API server, but Nuxt is not catching it!

Error page

<template>
  <section class="viewport content">
    <div class="container">
      <div class="row center-xs">
        <div class="col-xs-12">
          <h1 v-if="error.statusCode === 404">404</h1>
          <h1 v-else>An error occured</h1>
        </div>
      </div>
    </div>
  </section>
</template>

<script>
export default {
  props: ['error'],
  transition: 'page'
}
</script>
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1971">#c1971</a>)</em></sub></div>