spa global error handler

prevents white screens on critical vue errors and shows nuxt error page
This commit is contained in:
Pooya Parsa 2017-08-05 16:23:19 +04:30
parent 60b28e887f
commit a0cb08e451

View File

@ -28,6 +28,26 @@ let router
const NUXT = window.__NUXT__ || {}
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
createApp()
.then(mountApp)