2021-10-12 12:51:41 +00:00
|
|
|
<template>
|
2022-01-26 17:24:54 +00:00
|
|
|
<Suspense @resolve="onResolve">
|
2022-03-11 08:22:16 +00:00
|
|
|
<ErrorComponent v-if="error" :error="error" />
|
|
|
|
<App v-else />
|
2021-10-12 12:51:41 +00:00
|
|
|
</Suspense>
|
|
|
|
</template>
|
2021-12-21 14:44:35 +00:00
|
|
|
|
2022-03-18 10:57:53 +00:00
|
|
|
<script setup>
|
2022-07-15 22:15:31 +00:00
|
|
|
import { defineAsyncComponent, onErrorCaptured } from 'vue'
|
2022-07-21 14:29:03 +00:00
|
|
|
import { callWithNuxt, isNuxtError, showError, useError, useNuxtApp } from '#app'
|
2022-07-15 22:15:31 +00:00
|
|
|
|
|
|
|
const ErrorComponent = defineAsyncComponent(() => import('#build/error-component.mjs'))
|
2021-12-21 14:44:35 +00:00
|
|
|
|
2022-03-11 08:22:16 +00:00
|
|
|
const nuxtApp = useNuxtApp()
|
|
|
|
const onResolve = () => nuxtApp.callHook('app:suspense:resolve')
|
|
|
|
|
|
|
|
// vue:setup hook
|
|
|
|
const results = nuxtApp.hooks.callHookWith(hooks => hooks.map(hook => hook()), 'vue:setup')
|
|
|
|
if (process.dev && results && results.some(i => i && 'then' in i)) {
|
|
|
|
console.error('[nuxt] Error in `vue:setup`. Callbacks must be synchronous.')
|
2021-12-21 14:44:35 +00:00
|
|
|
}
|
2022-03-11 08:22:16 +00:00
|
|
|
|
|
|
|
// error handling
|
|
|
|
const error = useError()
|
|
|
|
onErrorCaptured((err, target, info) => {
|
|
|
|
nuxtApp.hooks.callHook('vue:error', err, target, info).catch(hookError => console.error('[nuxt] Error in `vue:error` hook', hookError))
|
2022-07-21 14:29:03 +00:00
|
|
|
if (process.server || (isNuxtError(err) && (err.fatal || err.unhandled))) {
|
|
|
|
callWithNuxt(nuxtApp, showError, [err])
|
2022-03-11 08:22:16 +00:00
|
|
|
}
|
|
|
|
})
|
2021-12-21 14:44:35 +00:00
|
|
|
</script>
|