Skip to content

Commit

Permalink
fix(vue-app): handle layout on client error (#7654)
Browse files Browse the repository at this point in the history
[release]
  • Loading branch information
Atinux committed Jul 2, 2020
1 parent 2f07f66 commit 191f66a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/vue-app/template/client.js
Expand Up @@ -60,7 +60,7 @@ const logs = NUXT.logs || []
// Setup global Vue error handler
if (!Vue.config.$nuxt) {
const defaultErrorHandler = Vue.config.errorHandler
Vue.config.errorHandler = (err, vm, info, ...rest) => {
Vue.config.errorHandler = async (err, vm, info, ...rest) => {
// Call other handler if exist
let handled = null
if (typeof defaultErrorHandler === 'function') {
Expand All @@ -76,7 +76,19 @@ if (!Vue.config.$nuxt) {

// Show Nuxt Error Page
if (nuxtApp && vm.$root[nuxtApp].error && info !== 'render function') {
vm.$root[nuxtApp].error(err)
const currentApp = vm.$root[nuxtApp]
<% if (features.layouts) { %>
// Load error layout
let layout = (NuxtError.options || NuxtError).layout
if (typeof layout === 'function') {
layout = layout(currentApp.context)
}
if (layout) {
await currentApp.loadLayout(layout).catch(() => {})
}
currentApp.setLayout(layout)
<% } %>
currentApp.error(err)
}
}

Expand Down

0 comments on commit 191f66a

Please sign in to comment.