diff --git a/docs/1.getting-started/8.error-handling.md b/docs/1.getting-started/8.error-handling.md
index b6067c6593..02cc9d1844 100644
--- a/docs/1.getting-started/8.error-handling.md
+++ b/docs/1.getting-started/8.error-handling.md
@@ -86,8 +86,10 @@ Customize the default error page by adding `~/error.vue` in the source directory
```vue [error.vue]
@@ -31,12 +33,12 @@ The error page has a single prop - `error` which contains an error for you to ha
The `error` object provides the following fields:
```ts
{
- url: string
statusCode: number
- statusMessage: string
- message: string
- description: string
- data: any
+ fatal: boolean
+ unhandled: boolean
+ statusMessage?: string
+ data?: unknown
+ cause?: unknown
}
```
diff --git a/packages/nuxt/src/app/entry.ts b/packages/nuxt/src/app/entry.ts
index dd4f4ab97a..72d889fb2c 100644
--- a/packages/nuxt/src/app/entry.ts
+++ b/packages/nuxt/src/app/entry.ts
@@ -10,6 +10,8 @@ import '#build/fetch.mjs'
import { applyPlugins, createNuxtApp } from './nuxt'
import type { CreateOptions } from './nuxt'
+import { createError } from './composables/error'
+
import '#build/css'
// @ts-expect-error virtual file
import plugins from '#build/plugins'
@@ -29,9 +31,9 @@ if (import.meta.server) {
try {
await applyPlugins(nuxt, plugins)
await nuxt.hooks.callHook('app:created', vueApp)
- } catch (err) {
- await nuxt.hooks.callHook('app:error', err)
- nuxt.payload.error = (nuxt.payload.error || err) as any
+ } catch (error) {
+ await nuxt.hooks.callHook('app:error', error)
+ nuxt.payload.error = nuxt.payload.error || createError(error as any)
}
if (ssrContext?._renderResponse) { throw new Error('skipping render') }
@@ -59,9 +61,9 @@ 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
+ async function handleVueError(error: any) {
+ await nuxt.callHook('app:error', error)
+ nuxt.payload.error = nuxt.payload.error || createError(error as any)
}
vueApp.config.errorHandler = handleVueError
diff --git a/packages/nuxt/src/app/nuxt.ts b/packages/nuxt/src/app/nuxt.ts
index e688b87ba0..7301418466 100644
--- a/packages/nuxt/src/app/nuxt.ts
+++ b/packages/nuxt/src/app/nuxt.ts
@@ -84,14 +84,7 @@ export interface NuxtPayload {
state: Record
once: Set
config?: Pick
- error?: Error | {
- url: string
- statusCode: number
- statusMessage: string
- message: string
- description: string
- data?: any
- } | null
+ error?: NuxtError | null
_errors: Record
[key: string]: unknown
}
diff --git a/packages/nuxt/src/core/runtime/nitro/error.ts b/packages/nuxt/src/core/runtime/nitro/error.ts
index 8b2aa16cef..c58bb75fcd 100644
--- a/packages/nuxt/src/core/runtime/nitro/error.ts
+++ b/packages/nuxt/src/core/runtime/nitro/error.ts
@@ -5,6 +5,7 @@ import { getRequestHeaders, send, setResponseHeader, setResponseStatus } from 'h
import { useRuntimeConfig } from '#internal/nitro'
import { useNitroApp } from '#internal/nitro/app'
import { isJsonRequest, normalizeError } from '#internal/nitro/utils'
+import type { NuxtPayload } from '#app'
export default async function errorhandler (error: H3Error, event) {
// Parse and normalize error
@@ -21,7 +22,7 @@ export default async function errorhandler (error: H3Error,
: '',
// TODO: check and validate error.data for serialisation into query
data: error.data as any
- }
+ } satisfies Partial & { url: string }
// Console output
if (error.unhandled || error.fatal) {
diff --git a/packages/nuxt/src/core/runtime/nitro/renderer.ts b/packages/nuxt/src/core/runtime/nitro/renderer.ts
index 964f76272c..8c63667db6 100644
--- a/packages/nuxt/src/core/runtime/nitro/renderer.ts
+++ b/packages/nuxt/src/core/runtime/nitro/renderer.ts
@@ -235,7 +235,7 @@ export default defineRenderHandler(async (event): Promise
+ ? getQuery(event) as unknown as NuxtPayload['error'] & { url: string }
: null
if (ssrError && ssrError.statusCode) {