Skip to content

Commit 30b6078

Browse files
committed
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
1 parent 088fc32 commit 30b6078

File tree

1 file changed

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

1 file changed

+5
-5
lines changed

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

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

5858
if(Math.random() <= 0.5)
59-
return status(418) // or status("I'm a teapot")
59+
return status(418)
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"`).
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 <DocLink href="/tutorial/getting-started/status-and-headers">Status and Headers</DocLink> for more on using status codes.
6666

6767
When `beforeHandle` returns a value, it will skip the handler and return the value instead.
6868

@@ -101,7 +101,7 @@ new Elysia()
101101
console.log('Run before handler')
102102

103103
if(Math.random() <= 0.5)
104-
return status(418) // or status("I'm a teapot")
104+
return status(418)
105105
}
106106
})
107107
.get('/2', () => 'Hello Elysia!')
@@ -122,7 +122,7 @@ new Elysia()
122122
console.log('This is executed before handler')
123123

124124
if(Math.random() <= 0.5)
125-
return status(418) // or status("I'm a teapot")
125+
return status(418)
126126
})
127127
// "beforeHandle" is applied
128128
.get('/auth', () => {
@@ -149,7 +149,7 @@ import { Elysia } from 'elysia'
149149

150150
new Elysia()
151151
.onBeforeHandle(({ query: { name }, status }) => {
152-
if(!name) return status(401) // or status("Unauthorized")
152+
if(!name) return status("Unauthorized")
153153
})
154154
.get('/auth', ({ query: { name = 'anon' } }) => {
155155
return `Hello ${name}!`

0 commit comments

Comments
 (0)