You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(tutorial): clarify status accepts both number and string names
- Remove '// or' comments in favor of clearer explanatory text
- Add note explaining 418 = 'I'm a teapot' with link to status tutorial
- Use status("Unauthorized") for auth example (clearer than 401)
- Keep status(418) for teapot examples
Copy file name to clipboardExpand all lines: docs/tutorial/getting-started/life-cycle/index.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,13 +56,13 @@ new Elysia()
56
56
console.log('This is executed before handler')
57
57
58
58
if(Math.random() <=0.5)
59
-
returnstatus(418)// or status("I'm a teapot")
59
+
returnstatus(418)
60
60
}
61
61
})
62
62
.get('/2', () =>'Hello Elysia!')
63
63
```
64
64
65
-
The `status` function accepts both numeric codes (`418`) and string status names (`"I'm a teapot"`).
65
+
Here we use `status(418)` which is the "I'm a teapot" status code. You can also use the string name directly: `status("I'm a teapot")`. See <DocLinkhref="/tutorial/getting-started/status-and-headers">Status and Headers</DocLink> for more on using status codes.
66
66
67
67
When `beforeHandle` returns a value, it will skip the handler and return the value instead.
68
68
@@ -101,7 +101,7 @@ new Elysia()
101
101
console.log('Run before handler')
102
102
103
103
if(Math.random() <=0.5)
104
-
returnstatus(418)// or status("I'm a teapot")
104
+
returnstatus(418)
105
105
}
106
106
})
107
107
.get('/2', () =>'Hello Elysia!')
@@ -122,7 +122,7 @@ new Elysia()
122
122
console.log('This is executed before handler')
123
123
124
124
if(Math.random() <=0.5)
125
-
returnstatus(418)// or status("I'm a teapot")
125
+
returnstatus(418)
126
126
})
127
127
// "beforeHandle" is applied
128
128
.get('/auth', () => {
@@ -149,7 +149,7 @@ import { Elysia } from 'elysia'
149
149
150
150
newElysia()
151
151
.onBeforeHandle(({ query: { name }, status }) => {
152
-
if(!name) returnstatus(401) // or status("Unauthorized")
0 commit comments