Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nuxt): handle errors when booting app with app:error #24376

Merged
merged 6 commits into from Nov 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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