Skip to content

Commit 042a3e8

Browse files
authored
Merge pull request #976 from bogeychan/bogey/974
fix: error responses with aot: false
2 parents 7578faa + 72ced01 commit 042a3e8

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

src/dynamic-handle.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { AnyElysia } from '.'
33
import {
44
ElysiaCustomStatusResponse,
55
ElysiaErrors,
6+
error,
67
NotFoundError,
78
ValidationError
89
} from './error'
@@ -65,6 +66,7 @@ export const createDynamicHandler = (app: AnyElysia) => {
6566
request,
6667
path,
6768
qi,
69+
error,
6870
redirect
6971
}
7072
) as unknown as Context & {

test/lifecycle/error.test.ts

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -120,43 +120,57 @@ describe('error', () => {
120120
expect(response.status).toBe(500)
121121
})
122122

123-
it('return correct number status on error function', async () => {
124-
const app = new Elysia().get('/', ({ error }) =>
125-
error(418, 'I am a teapot')
126-
)
123+
it.each([true, false])(
124+
'return correct number status on error function with aot: %p',
125+
async (aot) => {
126+
const app = new Elysia({ aot }).get('/', ({ error }) =>
127+
error(418, 'I am a teapot')
128+
)
127129

128-
const response = await app.handle(req('/'))
130+
const response = await app.handle(req('/'))
129131

130-
expect(response.status).toBe(418)
131-
})
132+
expect(response.status).toBe(418)
133+
}
134+
)
132135

133-
it('return correct named status on error function', async () => {
134-
const app = new Elysia().get('/', ({ error }) =>
135-
error("I'm a teapot", 'I am a teapot')
136-
)
136+
it.each([true, false])(
137+
'return correct named status on error function with aot: %p',
138+
async (aot) => {
139+
const app = new Elysia({ aot }).get('/', ({ error }) =>
140+
error("I'm a teapot", 'I am a teapot')
141+
)
137142

138-
const response = await app.handle(req('/'))
143+
const response = await app.handle(req('/'))
139144

140-
expect(response.status).toBe(418)
141-
})
145+
expect(response.status).toBe(418)
146+
}
147+
)
142148

143-
it('return correct number status without value on error function', async () => {
144-
const app = new Elysia().get('/', ({ error }) => error(418))
149+
it.each([true, false])(
150+
'return correct number status without value on error function with aot: %p',
151+
async (aot) => {
152+
const app = new Elysia({ aot }).get('/', ({ error }) => error(418))
145153

146-
const response = await app.handle(req('/'))
154+
const response = await app.handle(req('/'))
147155

148-
expect(response.status).toBe(418)
149-
expect(await response.text()).toBe("I'm a teapot")
150-
})
156+
expect(response.status).toBe(418)
157+
expect(await response.text()).toBe("I'm a teapot")
158+
}
159+
)
151160

152-
it('return correct named status without value on error function', async () => {
153-
const app = new Elysia().get('/', ({ error }) => error("I'm a teapot"))
161+
it.each([true, false])(
162+
'return correct named status without value on error function with aot: %p',
163+
async (aot) => {
164+
const app = new Elysia({ aot }).get('/', ({ error }) =>
165+
error("I'm a teapot")
166+
)
154167

155-
const response = await app.handle(req('/'))
168+
const response = await app.handle(req('/'))
156169

157-
expect(response.status).toBe(418)
158-
expect(await response.text()).toBe("I'm a teapot")
159-
})
170+
expect(response.status).toBe(418)
171+
expect(await response.text()).toBe("I'm a teapot")
172+
}
173+
)
160174

161175
it('handle error in order', async () => {
162176
let order = <string[]>[]

0 commit comments

Comments
 (0)