fix(vue-app): handle layout on client error (#7654)

[release]
This commit is contained in:
Sébastien Chopin 2020-07-02 18:22:12 +02:00 committed by GitHub
parent 2f07f66fb8
commit 191f66a19b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,7 +60,7 @@ const logs = NUXT.logs || []
// Setup global Vue error handler // Setup global Vue error handler
if (!Vue.config.$nuxt) { if (!Vue.config.$nuxt) {
const defaultErrorHandler = Vue.config.errorHandler 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 // Call other handler if exist
let handled = null let handled = null
if (typeof defaultErrorHandler === 'function') { if (typeof defaultErrorHandler === 'function') {
@ -76,7 +76,19 @@ if (!Vue.config.$nuxt) {
// Show Nuxt Error Page // Show Nuxt Error Page
if (nuxtApp && vm.$root[nuxtApp].error && info !== 'render function') { 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)
} }
} }