Skip to content

Commit

Permalink
fix(nuxt): handle errors when booting app with app:error (#24376)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu authored and manniL committed Dec 11, 2023
1 parent f955d24 commit 044f05d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/nuxt/src/app/entry.ts
Expand Up @@ -58,11 +58,17 @@ if (import.meta.client) {

const nuxt = createNuxtApp({ vueApp })

async function handleVueError(err: any) {
await nuxt.callHook('app:error', err)
nuxt.payload.error = (nuxt.payload.error || err) as any
}

vueApp.config.errorHandler = handleVueError

try {
await applyPlugins(nuxt, plugins)
} catch (err) {
await nuxt.callHook('app:error', err)
nuxt.payload.error = (nuxt.payload.error || err) as any
handleVueError(err)
}

try {
Expand All @@ -72,10 +78,13 @@ if (import.meta.client) {
await nuxt.hooks.callHook('app:mounted', vueApp)
await nextTick()
} catch (err) {
await nuxt.callHook('app:error', err)
nuxt.payload.error = (nuxt.payload.error || err) as any
handleVueError(err)
}

// If the errorHandler is not overridden by the user, we unset it
if (vueApp.config.errorHandler === handleVueError)
vueApp.config.errorHandler = undefined

return vueApp
}

Expand Down

0 comments on commit 044f05d

Please sign in to comment.