mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-13 09:33:54 +00:00
spa global error handler
prevents white screens on critical vue errors and shows nuxt error page
This commit is contained in:
parent
60b28e887f
commit
a0cb08e451
@ -28,6 +28,26 @@ let router
|
|||||||
const NUXT = window.__NUXT__ || {}
|
const NUXT = window.__NUXT__ || {}
|
||||||
NUXT.components = window.__COMPONENTS__ || null
|
NUXT.components = window.__COMPONENTS__ || null
|
||||||
|
|
||||||
|
// Setup global Vue error handler
|
||||||
|
const defaultErrorHandler = Vue.config.errorHandler
|
||||||
|
Vue.config.errorHandler = function (err, vm, info) {
|
||||||
|
// Show Nuxt Error Page
|
||||||
|
if(vm && vm.$root && vm.$root.$nuxt) {
|
||||||
|
vm.$root.$nuxt.error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call other handler if exist
|
||||||
|
if (typeof defaultErrorHandler === 'function') {
|
||||||
|
return defaultErrorHandler(...arguments)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log to console (default vue behavior)
|
||||||
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
console.warn(('Error in ' + info + ': "' + err.toString() + '"'), vm);
|
||||||
|
}
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
|
||||||
// Create and mount App
|
// Create and mount App
|
||||||
createApp()
|
createApp()
|
||||||
.then(mountApp)
|
.then(mountApp)
|
||||||
|
Loading…
Reference in New Issue
Block a user