useError()

Returns the global Nuxt error captured during SSR or client navigation.

Since Nuxt 3.0 Spec ↗

Syntax

const error = useError()

Returns

Ref<NuxtError | null> — Reactive ref to the active fatal error, or null.

Examples

<script setup lang="ts">
// Used inside error.vue
const error = useError()
</script>

<template>
  <h1>{{ error?.statusCode }}</h1>
  <p>{{ error?.message }}</p>
</template>
<script setup lang="ts">
const error = useError()
watchEffect(() => {
  if (error.value) console.error('App error', error.value)
})
</script>

Notes

Holds the error shown by the global `error.vue` page. The error is shared across server and client (serialized into the payload). Use `clearError()` to dismiss it and optionally redirect. For component-scoped recovery use `<NuxtErrorBoundary>`.

See also