mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
Update createError parameter signature to match h3 version in Nuxt.
This commit is contained in:
parent
51740fa1d7
commit
4bb74a7b19
@ -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>
|
||||
|
@ -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'
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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>
|
||||
```
|
||||
|
@ -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' })
|
||||
}
|
||||
})
|
||||
```
|
||||
|
@ -7,7 +7,7 @@ export const setInterval = import.meta.client
|
||||
: () => {
|
||||
if (import.meta.dev) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
status: 500,
|
||||
message: intervalError,
|
||||
})
|
||||
}
|
||||
|
@ -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}`,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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'`,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,8 @@ function renderStubMessage (name: string) {
|
||||
if (import.meta.client) {
|
||||
throw createError({
|
||||
fatal: true,
|
||||
statusCode: 500,
|
||||
statusMessage: message,
|
||||
status: 500,
|
||||
message: message,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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',
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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 || ''),
|
||||
})
|
||||
|
@ -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 = {
|
||||
|
2
test/fixtures/basic/pages/error.vue
vendored
2
test/fixtures/basic/pages/error.vue
vendored
@ -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' })
|
||||
|
2
test/fixtures/basic/server/api/error.ts
vendored
2
test/fixtures/basic/server/api/error.ts
vendored
@ -1,3 +1,3 @@
|
||||
export default defineEventHandler(() => {
|
||||
throw createError({ statusCode: 400 })
|
||||
throw createError({ status: 400 })
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user