Skip to content

Commit

Permalink
📘 feat: add number union to Elysia.onError.error
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Dec 27, 2024
1 parent b94dab2 commit 41f5db7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Bug fix:
- [#952](https://github.com/elysiajs/elysia/issues/952) onAfterResponse does not provide mapped response value unless aot is disabled
- `mapResponse.response` is `{}` if no response schema is provided
- Response doesn't reconcile when handler return `Response` is used with `mapResponse`
- `onError` now accept `error` as `number` when `Elysia.error` is thrown (but not return)

# 1.2.6 - 25 Dec 2024
Bug fix:
Expand Down
14 changes: 4 additions & 10 deletions example/a.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { Elysia, t, error } from '../src'
import { req } from '../test/utils'

const res = await new Elysia({
aot: false
})
.get('/', () => 'Hi')
.onError(({ code }) => {
if (code === 'NOT_FOUND')
return new Response("I'm a teapot", {
status: 418
})
const app = new Elysia()
.get('/', () => {
throw error("I'm a teapot")
})
.handle(req('/not-found'))
.listen(3000)

// console.log(await res.text())
// console.log(res.status)
17 changes: 17 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,23 @@ export type ErrorHandler<
Volatile['resolve']
>
>
| Prettify<
{
request: Request
code: number
error: Readonly<ElysiaCustomStatusResponse<number>>
set: Context['set']
} & Partial<
Singleton['derive'] &
Ephemeral['derive'] &
Volatile['derive']
> &
Partial<
Singleton['derive'] &
Ephemeral['resolve'] &
Volatile['resolve']
>
>
| Prettify<
{
[K in keyof T]: {
Expand Down

0 comments on commit 41f5db7

Please sign in to comment.