Nuxt.js: How to throw an error outside asyncData and fetch.

Created on 11 Apr 2017  路  2Comments  路  Source: nuxt/nuxt.js

Inspired by the solution posted in #429, I am looking to add error handling for some axios calls.

The code in that solution only throws errors in the browser, so I would like to instead throw a regular nuxt error page. However, the only way I know to do this is using the context.error() function inside asyncData or fetch.

How can I throw an error inside a plugin? Is there a way to get the global context or error handler?

This question is available on Nuxt.js community (#c482)
help-wanted question

Most helpful comment

Hi @benosman

It's possible on the client-side only via: $nuxt.error({ statusCode, message })

Example:

window.onNuxtReady(() => {
  $nuxt.error({ statusCode: 400, message: 'Teub' })
})

All 2 comments

Hi @benosman

It's possible on the client-side only via: $nuxt.error({ statusCode, message })

Example:

window.onNuxtReady(() => {
  $nuxt.error({ statusCode: 400, message: 'Teub' })
})

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikekidder picture mikekidder  路  3Comments

surmon-china picture surmon-china  路  3Comments

vadimsg picture vadimsg  路  3Comments

maicong picture maicong  路  3Comments

gary149 picture gary149  路  3Comments