Skip to content

Commit f2f50bb

Browse files
nikolovlazarbogeychanfecony
authored
🔧 fix: broken links & typos (#186)
* fix: broken links & typos * fix: undo required code formatting * fix: revert url-object * chore: fix frontmatter ident --------- Co-authored-by: bogeychan <[email protected]> Co-authored-by: Fecony <[email protected]>
1 parent 8aab745 commit f2f50bb

File tree

15 files changed

+196
-158
lines changed

15 files changed

+196
-158
lines changed

‎docs/at-glance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ const app = new Elysia()
137137
export type App = typeof app
138138
```
139139
140-
And on your client side:
140+
And on your client-side:
141141
142142
```typescript
143143
// client.ts

‎docs/essential/path.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ For instance, we can extract the user ID from the pathname, we can do something
5757
```typescript
5858
import { Elysia } from 'elysia'
5959

60-
new Elysia()
61-
.get('/id/:id', ({ params: { id } }) => id)
62-
.listen(3000)
60+
new Elysia().get('/id/:id', ({ params: { id } }) => id).listen(3000)
6361
```
6462

6563
We create a dynamic path with `/id/:id` which tells Elysia to match any path up until `/id` and after it could be any value, which is then stored as **params** object.
@@ -128,9 +126,7 @@ However, when you need a value of the path to be more dynamic and capture the re
128126
Wildcard can capture the value after segment regardless of amount by using "\*".
129127

130128
```typescript
131-
new Elysia()
132-
.get('/id/*', ({ params }) => params['*'])
133-
.listen(3000)
129+
new Elysia().get('/id/*', ({ params }) => params['*']).listen(3000)
134130
```
135131

136132
Sending a request to the server should return the response as the following:

‎docs/essential/route.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ Any HTTP method that matches the path, will be handled as follows:
159159

160160
## 404
161161

162-
If no path matches the defined routes, Elysia will pass the request to `error` lifecycle before returning a "NOT_FOUND" with an HTTP status of 404.
162+
If no path matches the defined routes, Elysia will pass the request to `error` life cycle before returning a "NOT_FOUND" with an HTTP status of 404.
163163

164164
::: tip
165165
HTTP Status is used to indicate the type of response. By default if everything is correct, the server will return a '200 OK' status code (If a route matches and there is no error, Elysia will return 200 as default)
166166

167167
If the server fails to find any route to handle, like in this case, then the server shall return a '404 NOT FOUND' status code.
168168
:::
169169

170-
For Elysia, we can handle a custom 404 error by returning a value from 'error` lifecycle like this:
170+
For Elysia, we can handle a custom 404 error by returning a value from 'error` life cycle like this:
171171

172172
```typescript
173173
import { Elysia } from 'elysia'
@@ -188,4 +188,4 @@ When navigating to your web server, you should see the result as follows:
188188
| / | POST | Route not found :\( |
189189
| /hi | GET | Route not found :\( |
190190

191-
You can learn more about lifecycle and error handling in [Lifecycle Event](/essential/life-cycle) and [error handling](/life-cycle/on-error)
191+
You can learn more about life cycle and error handling in [Life Cycle Events](/essential/life-cycle#events) and [Error Handling](/life-cycle/on-error).

‎docs/integrations/astro.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ head:
1818

1919
With [Astro Endpoint](https://docs.astro.build/en/core-concepts/endpoints/), we can run Elysia on Astro directly.
2020

21-
1. Set **output** to **server** in **astro.config.mjs**
21+
1. Set **output** to **server** in **astro.config.mjs**
22+
2223
```javascript
2324
// astro.config.mjs
24-
import { defineConfig } from 'astro/config';
25+
import { defineConfig } from 'astro/config'
2526

2627
// https://astro.build/config
2728
export default defineConfig({
2829
output: 'server' // [!code ++]
2930
})
3031
```
32+
3133
2. Create **pages/[...slugs].ts**
3234
3. Create or import an existing Elysia server in **[...slugs].ts**
3335
4. Export the handler with the name of method you want to expose
@@ -53,7 +55,7 @@ Elysia will work normally as expected because of WinterCG compliance.
5355
We recommended running [Astro on Bun](https://docs.astro.build/en/recipes/bun) as Elysia is designed to be run on Bun
5456

5557
::: tip
56-
You can run Elysia server without running Astro on Bun thanks to WinterCG support.
58+
You can run Elysia server without running Astro on Bun thanks to WinterCG support.
5759

5860
However some plugins like **Elysia Static** may not work if you are running Astro on Node.
5961
:::
@@ -63,6 +65,7 @@ With this approach, you can have co-location of both frontend and backend in a s
6365
Please refer to [Astro Endppoint](https://docs.astro.build/en/core-concepts/endpoints/) for more information.
6466

6567
## Prefix
68+
6669
If you place an Elysia server not in the root directory of the app router, you need to annotate the prefix to the Elysia server.
6770

6871
For example, if you place Elysia server in **apps/api/[...slugs].ts**, you need to annotate prefix as **/api** to Elysia server.

‎docs/life-cycle/before-handle.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ import { validateSession } from '@services/users'
3838
new Elysia()
3939
.get('/', () => 'hi', {
4040
beforeHandle({ set, cookie: { session } }) {
41-
if(!validateSession(session.value))
42-
return set.status = 'Unauthorized'
41+
if (!validateSession(session.value))
42+
return (set.status = 'Unauthorized')
4343
}
4444
})
4545
.listen(3000)
@@ -53,6 +53,7 @@ The response should be listed as follows:
5353
| ✅ | Hi |
5454

5555
## Guard
56+
5657
When we need to apply the same before handle to multiple routes, we can use [guard](#guard) to apply the same before handle to multiple routes.
5758

5859
```typescript

‎docs/life-cycle/on-error.md

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
---
22
title: Error Handling - ElysiaJS
33
head:
4-
- - meta
5-
- property: 'og:title'
6-
content: Error Handling - ElysiaJS
4+
- - meta
5+
- property: 'og:title'
6+
content: Error Handling - ElysiaJS
77

8-
- - meta
9-
- name: 'description'
10-
content: Execute when an error is thrown in any other life-cycle at least once. Designed to capture and resolve an unexpected error, it's recommended to use on Error in the following situation. To provide custom error message. Fail safe or an error handler or retrying a request. Logging and analytics.
8+
- - meta
9+
- name: 'description'
10+
content: Execute when an error is thrown in any other life-cycle at least once. Designed to capture and resolve an unexpected error, it's recommended to use on Error in the following situation. To provide custom error message. Fail safe or an error handler or retrying a request. Logging and analytics.
1111

12-
- - meta
13-
- property: 'og:description'
14-
content: Execute when an error is thrown in any other life-cycle at least once. Designed to capture and resolve an unexpected error, it's recommended to use on Error in the following situation. To provide custom error message. Fail safe or an error handler or retrying a request. Logging and analytics.
12+
- - meta
13+
- property: 'og:description'
14+
content: Execute when an error is thrown in any other life-cycle at least once. Designed to capture and resolve an unexpected error, it's recommended to use on Error in the following situation. To provide custom error message. Fail safe or an error handler or retrying a request. Logging and analytics.
1515
---
1616

1717
# Error Handling
18+
1819
**On Error** is the only life-cycle event that is not always executed on each request, but only when an error is thrown in any other life-cycle at least once.
1920

2021
Designed to capture and resolve an unexpected error, its recommended to use on Error in the following situation:
21-
- To provide custom error message
22-
- Fail safe or an error handler or retrying a request
23-
- Logging and analytic
22+
23+
- To provide custom error message
24+
- Fail safe or an error handler or retrying a request
25+
- Logging and analytic
2426

2527
## Example
28+
2629
Elysia catches all the errors thrown in the handler, classifies the error code, and pipes them to `onError` middleware.
2730

2831
```typescript
@@ -44,6 +47,7 @@ It's important that `onError` must be called before the handler we want to apply
4447
:::
4548
4649
For example, returning custom 404 messages:
50+
4751
```typescript
4852
import { Elysia, NotFoundError } from 'elysia'
4953

@@ -55,24 +59,28 @@ new Elysia()
5559
return 'Not Found :('
5660
}
5761
})
58-
.post('/', () => {
59-
throw new NotFoundError();
60-
})
62+
.post('/', () => {
63+
throw new NotFoundError()
64+
})
6165
.listen(8080)
6266
```
6367
6468
## Context
69+
6570
`onError` Context is extends from `Context` with additional properties of the following:
66-
- error: Error object thrown
67-
- code: Error Code
71+
72+
- error: Error object thrown
73+
- code: Error Code
6874
6975
### Error Code
76+
7077
Elysia error code consists of:
71-
- NOT_FOUND
72-
- INTERNAL_SERVER_ERROR
73-
- VALIDATION
74-
- PARSE
75-
- UNKNOWN
78+
79+
- NOT_FOUND
80+
- INTERNAL_SERVER_ERROR
81+
- VALIDATION
82+
- PARSE
83+
- UNKNOWN
7684
7785
By default, the thrown error code is `unknown`.
7886
@@ -81,6 +89,7 @@ If no error response is returned, the error will be returned using `error.name`.
8189
:::
8290
8391
## Custom Error
92+
8493
Elysia supports custom error both in the type-level and implementation level.
8594
8695
To provide a custom error code, we can use `Eylsia.error` to add a custom error code, helping us to easily classify and narrow down the error type for full type safety with auto-complete as the following:
@@ -97,31 +106,33 @@ new Elysia()
97106
MyError
98107
})
99108
.onError(({ code, error }) => {
100-
switch(code) {
109+
switch (code) {
101110
// With auto-completion
102111
case 'MyError':
103112
// With type narrowing
104113
// Error is typed as CustomError
105114
return error
106115
}
107116
})
108-
.get('/', () => {
109-
throw new MyError('Hello Error');
110-
})
117+
.get('/', () => {
118+
throw new MyError('Hello Error')
119+
})
111120
```
112121
113122
Properties of `error` code is based on the properties of `error`, the said properties will be used to classify the error code.
114123
115124
## Local Error
116-
Same as others life-cycle, we provide an error into an [scope](/new/essential/scope) using guard:
125+
126+
Same as others life-cycle, we provide an error into an [scope](/essential/scope) using guard:
127+
117128
```typescript
118129
new Elysia()
119130
.get('/', () => 'Hello', {
120131
beforeHandle({ set, request: { headers } }) {
121-
if(!isSignIn(headers)) {
132+
if (!isSignIn(headers)) {
122133
set.status = 401
123134

124-
throw new Error("Unauthorized")
135+
throw new Error('Unauthorized')
125136
}
126137
},
127138
error({ error }) {

‎docs/life-cycle/overview.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ head:
2020
</script>
2121

2222
# Life Cycle
23+
2324
It's recommended that you have read [Essential life-cycle](/essential/life-cycle) for better understanding of Elysia's Life Cycle.
2425

2526
Life Cycle allows us to intercept an important event at the predefined point allowing us to customize the behavior of our server as needed.
2627

2728
Elysia's Life Cycle event can be illustrated as the following.
2829
![Elysia Life Cycle Graph](/assets/lifecycle.webp)
2930

30-
Below are the request lifecycle available in Elysia:
31+
Below are the request life cycle available in Elysia:
3132

3233
<Deck>
3334
<Card title="Request" href="request">
@@ -62,6 +63,7 @@ Below are the request lifecycle available in Elysia:
6263
---
6364

6465
Every life-cycle could be apply at both:
66+
6567
1. Local Hook (route)
6668
2. Global Hook
6769

0 commit comments

Comments
 (0)