Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/patterns/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import TutorialBadge from '../components/arona/badge.vue'
import Card from '../components/nearl/card.vue'
import Deck from '../components/nearl/card-deck.vue'
import Playground from '../components/nearl/playground.vue'
import DocLink from '../components/xiao/doc-link/doc-link.vue'

const demo = new Elysia()
.onError(({ code }) => {
Expand Down Expand Up @@ -308,6 +309,8 @@ new Elysia()
})
```

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">Status</DocLink> for more on using status codes.

<Playground
:elysia="demo"
/>
2 changes: 2 additions & 0 deletions docs/tutorial/getting-started/life-cycle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ new Elysia()
.get('/2', () => 'Hello Elysia!')
```

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">Status</DocLink> for more on using status codes.

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

This is useful for things like authentication, where you want to return a `401 Unauthorized` response if the user is not authenticated.
Expand Down