Skip to content

Commit 63cd933

Browse files
authored
Update error-handling.md
Updated the error handling docs to provide a more in depth example of how to implement and use custom errors, and errors out of the box e.g NotFoundError
1 parent 79d2e48 commit 63cd933

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

docs/patterns/error-handling.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ It's important that `onError` must be call before handler you want to apply
3737

3838
For example, returning custom 404 messages:
3939
```typescript
40-
import { Elysia } from 'elysia'
40+
import { Elysia, NotFoundError } from 'elysia'
4141

4242
new Elysia()
4343
.onError(({ code, error, set }) => {
@@ -47,6 +47,9 @@ new Elysia()
4747
return 'Not Found :('
4848
}
4949
})
50+
.post('/', () => {
51+
throw new NotFoundError();
52+
})
5053
.listen(8080)
5154
```
5255

@@ -119,6 +122,9 @@ new Elysia()
119122
return error
120123
}
121124
})
125+
.get('/', () => {
126+
throw new CustomError('Hello Error');
127+
})
122128
```
123129

124130
## Catching all error

0 commit comments

Comments
 (0)