Skip to content

Commit a0cb08e

Browse files
author
Pooya Parsa
committed
spa global error handler
prevents white screens on critical vue errors and shows nuxt error page
1 parent 60b28e8 commit a0cb08e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/app/client.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ let router
2828
const NUXT = window.__NUXT__ || {}
2929
NUXT.components = window.__COMPONENTS__ || null
3030

31+
// Setup global Vue error handler
32+
const defaultErrorHandler = Vue.config.errorHandler
33+
Vue.config.errorHandler = function (err, vm, info) {
34+
// Show Nuxt Error Page
35+
if(vm && vm.$root && vm.$root.$nuxt) {
36+
vm.$root.$nuxt.error(err)
37+
}
38+
39+
// Call other handler if exist
40+
if (typeof defaultErrorHandler === 'function') {
41+
return defaultErrorHandler(...arguments)
42+
}
43+
44+
// Log to console (default vue behavior)
45+
if (process.env.NODE_ENV !== 'production') {
46+
console.warn(('Error in ' + info + ': "' + err.toString() + '"'), vm);
47+
}
48+
console.error(err);
49+
}
50+
3151
// Create and mount App
3252
createApp()
3353
.then(mountApp)

0 commit comments

Comments
 (0)