Skip to content

Commit 088fc32

Browse files
committed
docs(tutorial): show string status names in lifecycle examples
Add inline comments showing string alternatives: - status(418) // or status("I'm a teapot") - status(401) // or status("Unauthorized") Also add explanatory note that status() accepts both formats.
1 parent 7894014 commit 088fc32

File tree

1 file changed

+6
-4
lines changed
  • docs/tutorial/getting-started/life-cycle

1 file changed

+6
-4
lines changed

docs/tutorial/getting-started/life-cycle/index.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ new Elysia()
5656
console.log('This is executed before handler')
5757

5858
if(Math.random() <= 0.5)
59-
return status(418)
59+
return status(418) // or status("I'm a teapot")
6060
}
6161
})
6262
.get('/2', () => 'Hello Elysia!')
6363
```
6464

65+
The `status` function accepts both numeric codes (`418`) and string status names (`"I'm a teapot"`).
66+
6567
When `beforeHandle` returns a value, it will skip the handler and return the value instead.
6668

6769
This is useful for things like authentication, where you want to return a `401 Unauthorized` response if the user is not authenticated.
@@ -99,7 +101,7 @@ new Elysia()
99101
console.log('Run before handler')
100102

101103
if(Math.random() <= 0.5)
102-
return status(418)
104+
return status(418) // or status("I'm a teapot")
103105
}
104106
})
105107
.get('/2', () => 'Hello Elysia!')
@@ -120,7 +122,7 @@ new Elysia()
120122
console.log('This is executed before handler')
121123

122124
if(Math.random() <= 0.5)
123-
return status(418)
125+
return status(418) // or status("I'm a teapot")
124126
})
125127
// "beforeHandle" is applied
126128
.get('/auth', () => {
@@ -147,7 +149,7 @@ import { Elysia } from 'elysia'
147149

148150
new Elysia()
149151
.onBeforeHandle(({ query: { name }, status }) => {
150-
if(!name) return status(401)
152+
if(!name) return status(401) // or status("Unauthorized")
151153
})
152154
.get('/auth', ({ query: { name = 'anon' } }) => {
153155
return `Hello ${name}!`

0 commit comments

Comments
 (0)