Movatterモバイル変換


[0]ホーム

URL:


Wayback Machine
20 captures
16 Nov 2022 - 10 Aug 2025
AugSEPOct
26
202220232024
success
fail
COLLECTED BY
Collection:Common Crawl
Web crawl data from Common Crawl.
TIMESTAMPS
loading
The Wayback Machine - http://web.archive.org/web/20230926022127/https://nuxt.com/docs/api/utils/create-error
🎤 Nuxt Nation is coming - The largest online Nuxt Conference is happening on October 18-19, 2023.Register

createError

You can use this function to create an error object with additional metadata. It is usable in both the Vue and Nitro portions of your app, and is meant to be thrown.

Parameters:

  • err: { cause, data, message, name, stack, statusCode, statusMessage, fatal }

Throwing Errors in Your Vue App

If you throw an error created withcreateError:

  • on server-side, it will trigger a full-screen error page which you can clear withclearError.
  • on client-side, it will throw a non-fatal error for you to handle. If you need to trigger a full-screen error page, then you can do this by settingfatal: true.

Example

pages/movies/[slug].vue
<scriptsetuplang="ts">constroute=useRoute()const {data }=awaituseFetch(`/api/movies/${route.params.slug}`)if (!data.value) {throwcreateError({statusCode:404,statusMessage:'Page Not Found' })}</script>

Throwing Errors in API Routes

UsecreateError to trigger error handling in server API routes.

Example

exportdefaulteventHandler(()=> {throwcreateError({statusCode:404,statusMessage:'Page Not Found'  })})

[8]ページ先頭

©2009-2025 Movatter.jp