fix(nuxt3): only warn within error handling routine (#3394)

This commit is contained in:
Daniel Roe 2022-02-25 16:33:27 +00:00 committed by GitHub
parent e45a780714
commit 2b3dbed594
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -103,9 +103,6 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>((nuxtApp) => {
const route: Route = reactive(getRouteFromPath(process.client ? window.location.href : nuxtApp.ssrContext.url))
async function handleNavigation (url: string, replace?: boolean): Promise<void> {
if (process.dev && process.client && !hooks.error.length) {
console.warn('No error handlers registered to handle middleware errors. You can register an error handler with `router.onError()`')
}
try {
// Resolve route
const to = getRouteFromPath(url)
@ -131,6 +128,9 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>((nuxtApp) => {
await middleware(to, route)
}
} catch (err) {
if (process.dev && !hooks.error.length) {
console.warn('No error handlers registered to handle middleware errors. You can register an error handler with `router.onError()`', err)
}
for (const handler of hooks.error) {
await handler(err)
}