Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/nuxtPublic

Commit988ac15

Browse files
authored
refactor(nitro,nuxt,vite,webpack): usestatus/statusText + deprecate old props (#33912)
1 parent5b16a51 commit988ac15

File tree

37 files changed

+138
-121
lines changed

37 files changed

+138
-121
lines changed

‎docs/1.getting-started/07.routing.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ definePageMeta({
135135

136136
Nuxt offers route validation via the`validate` property in[`definePageMeta()`](/docs/4.x/api/utils/define-page-meta) in each page you wish to validate.
137137

138-
The`validate` property accepts the`route` as an argument. You can return a boolean value to determine whether or not this is a valid route to be rendered with this page. If you return`false`, this will cause a 404 error. You can also directly return an object with`statusCode`/`statusMessage` to customize the error returned.
138+
The`validate` property accepts the`route` as an argument. You can return a boolean value to determine whether or not this is a valid route to be rendered with this page. If you return`false`, this will cause a 404 error. You can also directly return an object with`status`/`statusText` to customize the error returned.
139139

140140
If you have a more complex use case, then you can use anonymous route middleware instead.
141141

‎docs/1.getting-started/12.error-handling.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const handleError = () => clearError({ redirect: '/' })
9999
100100
<template>
101101
<div>
102-
<h2>{{ error?.statusCode }}</h2>
102+
<h2>{{ error?.status }}</h2>
103103
<button @click="handleError">
104104
Clear errors
105105
</button>
@@ -140,7 +140,7 @@ If you are running on Node 16 and you set any cookies when rendering your error
140140
###`useError`
141141

142142
```ts [TS Signature]
143-
function useError ():Ref<Error| { url,statusCode, statusMessage, message, description, data }>
143+
function useError ():Ref<Error| { url,status, statusText, message, description, data }>
144144
```
145145

146146
Thisfunction will return the global Nuxt error that is being handled.
@@ -152,7 +152,7 @@ Read more about `useError` composable.
152152
###`createError`
153153

154154
```ts [TS Signature]
155-
function createError (err: string | { cause, data, message, name, stack,statusCode, statusMessage, fatal }): Error
155+
function createError (err: string | { cause, data, message, name, stack,status, statusText, fatal }): Error
156156
```
157157

158158
Createanerrorobjectwithadditionalmetadata.Youcanpassastringtobesetastheerror`message`oranobjectcontainingerrorproperties.ItisusableinboththeVueandServerportionsofyourapp,andismeanttobethrown.
@@ -168,8 +168,8 @@ const { data } = await useFetch(`/api/movies/${route.params.slug}`)
168168
169169
if (!data.value) {
170170
throw createError({
171-
statusCode: 404,
172-
statusMessage: 'Page Not Found',
171+
status: 404,
172+
statusText: 'Page Not Found',
173173
})
174174
}
175175
</script>
@@ -182,7 +182,7 @@ Read more about `createError` util.
182182
###`showError`
183183

184184
```ts [TS Signature]
185-
function showError (err: string | Error | {statusCode, statusMessage }): Error
185+
function showError (err: string | Error | {status, statusText }): Error
186186
```
187187

188188
Youcancallthisfunction at any point on client-side, or (onserverside) directly within middleware, plugins or `setup()` functions. It will trigger a full-screen error page which you can clear with [`clearError`](/docs/4.x/getting-started/error-handling#clearerror).

‎docs/2.directory-structure/1.app/3.error.md‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const props = defineProps<{ error: NuxtError }>()
1616
1717
<template>
1818
<div>
19-
<h1>{{ error.statusCode }}</h1>
19+
<h1>{{ error.status }}</h1>
2020
<NuxtLink to="/">Go back home</NuxtLink>
2121
</div>
2222
</template>
@@ -31,21 +31,25 @@ The error page has a single prop - `error` which contains an error for you to ha
3131
The`error` object provides the following fields:
3232
```ts
3333
interfaceNuxtError {
34-
statusCode:number
34+
status:number
3535
fatal:boolean
3636
unhandled:boolean
37-
statusMessage?:string
37+
statusText?:string
3838
data?:unknown
3939
cause?:unknown
40+
// legacy/deprecated equivalent of `status`
41+
statusCode:number
42+
// legacy/deprecated equivalent of `statusText`
43+
statusMessage?:string
4044
}
4145
```
4246

4347
If you have an error with custom fields they will be lost; you should assign them to`data` instead:
4448

4549
```ts
4650
throwcreateError({
47-
statusCode:404,
48-
statusMessage:'Page Not Found',
51+
status:404,
52+
statusText:'Page Not Found',
4953
data: {
5054
myCustomField:true,
5155
},

‎docs/2.directory-structure/1.server.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ export default defineEventHandler((event) => {
295295

296296
if (!Number.isInteger(id)) {
297297
throwcreateError({
298-
statusCode:400,
299-
statusMessage:'ID should be an integer',
298+
status:400,
299+
statusText:'ID should be an integer',
300300
})
301301
}
302302
return'All good'

‎docs/3.guide/1.concepts/2.nuxt-lifecycle.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ After this step, Nuxt calls the [`app:created`](/docs/4.x/api/advanced/hooks#app
5454
After initializing plugins and before executing middleware, Nuxt calls the`validate` method if it is defined in the`definePageMeta` function. The`validate` method, which can be synchronous or asynchronous, is often used to validate dynamic route parameters.
5555

5656
- The`validate` function should return`true` if the parameters are valid.
57-
- If validation fails, it should return`false` or an object containing a`statusCode` and/or`statusMessage` to terminate the request.
57+
- If validation fails, it should return`false` or an object containing a`status` and/or`statusText` to terminate the request.
5858

5959
For more information, see the[Route Validation documentation](/docs/4.x/getting-started/routing#route-validation).
6060

‎docs/3.guide/5.recipes/3.custom-usefetch.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ import type { UseFetchOptions } from 'nuxt/app'
9898

9999
interfaceCustomError {
100100
message:string
101-
statusCode:number
101+
status:number
102102
}
103103

104104
exportfunction useAPI<T> (

‎docs/3.guide/5.recipes/4.sessions-and-authentication.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default defineEventHandler(async (event) => {
6565
return {}
6666
}
6767
throwcreateError({
68-
statusCode:401,
68+
status:401,
6969
message:'Bad credentials',
7070
})
7171
})

‎docs/4.api/2.composables/use-error.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ You can use this composable in your components, pages, or plugins to access or r
2222

2323
```ts
2424
interfaceNuxtError<DataT=unknown> {
25-
statusCode:number
26-
statusMessage:string
25+
status:number
26+
statusText:string
2727
message:string
2828
data?:DataT
2929
error?:true

‎docs/4.api/3.utils/create-error.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ You can use this function to create an error object with additional metadata. It
1212

1313
##Parameters
1414

15-
-`err`:`string | { cause, data, message, name, stack,statusCode, statusMessage, fatal }`
15+
-`err`:`string | { cause, data, message, name, stack,status, statusText, fatal }`
1616

17-
You can pass either a string or an object to the`createError` function. If you pass a string, it will be used as the error`message`, and the`statusCode` will default to`500`. If you pass an object, you can set multiple properties of the error, such as`statusCode`,`message`, and other error properties.
17+
You can pass either a string or an object to the`createError` function. If you pass a string, it will be used as the error`message`, and the`status` will default to`500`. If you pass an object, you can set multiple properties of the error, such as`status`,`message`, and other error properties.
1818

1919
##In Vue App
2020

@@ -30,7 +30,7 @@ If you throw an error created with `createError`:
3030
const route = useRoute()
3131
const { data } = await useFetch(`/api/movies/${route.params.slug}`)
3232
if (!data.value) {
33-
throw createError({statusCode: 404,statusMessage: 'Page Not Found' })
33+
throw createError({status: 404,statusText: 'Page Not Found' })
3434
}
3535
</script>
3636
```
@@ -44,12 +44,12 @@ Use `createError` to trigger error handling in server API routes.
4444
```ts [server/api/error.ts]
4545
exportdefaulteventHandler(()=> {
4646
throwcreateError({
47-
statusCode:404,
48-
statusMessage:'Page Not Found',
47+
status:404,
48+
statusText:'Page Not Found',
4949
})
5050
})
5151
```
5252

53-
In API routes, using`createError` by passing an object with a short`statusMessage` is recommended because it can be accessed on the client side. Otherwise, a`message` passed to`createError` on an API route will not propagate to the client. Alternatively, you can use the`data` property to pass data back to the client. In any case, always consider avoiding to put dynamic user input to the message to avoid potential security issues.
53+
In API routes, using`createError` by passing an object with a short`statusText` is recommended because it can be accessed on the client side. Otherwise, a`message` passed to`createError` on an API route will not propagate to the client. Alternatively, you can use the`data` property to pass data back to the client. In any case, always consider avoiding to put dynamic user input to the message to avoid potential security issues.
5454

5555
:read-more{to="/docs/4.x/getting-started/error-handling"}

‎docs/4.api/3.utils/define-nuxt-route-middleware.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ You can use route middleware to throw errors and show helpful error messages:
3939
```ts [app/middleware/error.ts]
4040
exportdefaultdefineNuxtRouteMiddleware((to)=> {
4141
if (to.params.id==='1') {
42-
throwcreateError({statusCode:404,statusMessage:'Page Not Found' })
42+
throwcreateError({status:404,statusText:'Page Not Found' })
4343
}
4444
})
4545
```

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp