Update createError parameter signature to match h3 version in Nuxt.

This commit is contained in:
Ray Tien 2024-06-01 08:13:23 +08:00
parent 51740fa1d7
commit 4bb74a7b19
14 changed files with 22 additions and 22 deletions

View File

@ -162,8 +162,8 @@ const { data } = await useFetch(`/api/movies/${route.params.slug}`)
if (!data.value) {
throw createError({
statusCode: 404,
statusMessage: 'Page Not Found'
status: 404,
message: 'Page Not Found'
})
}
</script>

View File

@ -285,8 +285,8 @@ export default defineEventHandler((event) => {
if (!Number.isInteger(id)) {
throw createError({
statusCode: 400,
statusMessage: 'ID should be an integer',
status: 400,
message: 'ID should be an integer',
})
}
return 'All good'

View File

@ -46,8 +46,8 @@ If you have an error with custom fields they will be lost; you should assign the
```ts
throw createError({
statusCode: 404,
statusMessage: 'Page Not Found',
status: 404,
message: 'Page Not Found',
data: {
myCustomField: true
}

View File

@ -28,7 +28,7 @@ If you throw an error created with `createError`:
const route = useRoute()
const { data } = await useFetch(`/api/movies/${route.params.slug}`)
if (!data.value) {
throw createError({ statusCode: 404, statusMessage: 'Page Not Found' })
throw createError({ status: 404, message: 'Page Not Found' })
}
</script>
```

View File

@ -39,7 +39,7 @@ You can use route middleware to throw errors and show helpful error messages:
```ts [middleware/error.ts]
export default defineNuxtRouteMiddleware((to) => {
if (to.params.id === '1') {
throw createError({ statusCode: 404, statusMessage: 'Page Not Found' })
throw createError({ status: 404, message: 'Page Not Found' })
}
})
```

View File

@ -7,7 +7,7 @@ export const setInterval = import.meta.client
: () => {
if (import.meta.dev) {
throw createError({
statusCode: 500,
status: 500,
message: intervalError,
})
}

View File

@ -18,8 +18,8 @@ export default defineComponent({
if (!component) {
throw createError({
statusCode: 404,
statusMessage: `Island component not found: ${props.context.name}`,
status: 404,
message: `Island component not found: ${props.context.name}`,
})
}

View File

@ -3,8 +3,8 @@ import { createError } from '../composables/error'
function renderStubMessage (name: string) {
throw createError({
fatal: true,
statusCode: 500,
statusMessage: `${name} is provided by @nuxt/image. Check your console to install it or run 'npx nuxi@latest module add @nuxt/image'`,
status: 500,
message: `${name} is provided by @nuxt/image. Check your console to install it or run 'npx nuxi@latest module add @nuxt/image'`,
})
}

View File

@ -6,8 +6,8 @@ function renderStubMessage (name: string) {
if (import.meta.client) {
throw createError({
fatal: true,
statusCode: 500,
statusMessage: message,
status: 500,
message: message,
})
}
}

View File

@ -260,8 +260,8 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
if (ssrError && !('__unenv__' in event.node.req) /* allow internal fetch */) {
throw createError({
statusCode: 404,
statusMessage: 'Page Not Found: /__nuxt_error',
status: 404,
message: 'Page Not Found: /__nuxt_error',
})
}

View File

@ -59,7 +59,7 @@ function createRunner () {
const message = `[vite-node] [TransformError] ${errorData?.message || '-'}`
consola.error(message, errorData)
throw createError({
statusMessage: 'Vite Error',
message: 'Vite Error',
message,
stack: `${message}\nat ${id}\n` + (errorData?.stack || ''),
})

View File

@ -140,10 +140,10 @@ function createViteNodeApp (ctx: ViteBuildContext, invalidates: Set<string> = ne
return eventHandler(async (event) => {
const moduleId = decodeURI(event.path).substring(1)
if (moduleId === '/') {
throw createError({ statusCode: 400 })
throw createError({ status: 400 })
}
if (isAbsolute(moduleId) && !isFileServingAllowed(moduleId, viteServer)) {
throw createError({ statusCode: 403 /* Restricted */ })
throw createError({ status: 403 /* Restricted */ })
}
const module = await node.fetchModule(moduleId).catch((err) => {
const errorData = {

View File

@ -12,7 +12,7 @@ const { data, error } = await useAsyncData(() => {
if (error.value) {
useCookie('some-error').value = 'was set'
throw createError({ statusCode: 422, fatal: true, statusMessage: 'This is a custom error' })
throw createError({ status: 422, fatal: true, message: 'This is a custom error' })
}
const state = ref({ attr: 'Hello World' })

View File

@ -1,3 +1,3 @@
export default defineEventHandler(() => {
throw createError({ statusCode: 400 })
throw createError({ status: 400 })
})