Open ap0nia opened 1 month ago
1.1.16
Darwin 23.4.0 arm64 arm
.mapResponse behaves differently depending on whether it's invoked before or after other methods. This is based on the mapResponse test here
.mapResponse
mapResponse before the method handler will map the response.
mapResponse
it('work global', async () => { const app = new Elysia() .mapResponse(() => new Response('A')) .get('/', (context) => context.error(401)) const res = await app.handle(req('/')).then((x) => x.text()) expect(res).toBe('A') })
mapResponse after the request handler will not map the response (the route returns an error).
it('work global', async () => { const app = new Elysia() .get('/', (context) => context.error(401)) .mapResponse(() => new Response('A')) const res = await app.handle(req('/')).then((x) => x.text()) expect(res).toBe('A') })
Same as case 1, but for some reason printing out the context will mean the response is not mapped.
context
it('work global', async () => { const app = new Elysia() .mapResponse((context) => { console.log(context) return new Response('A') ) .get('/', (context) => context.error(401)) const res = await app.handle(req('/')).then((x) => x.text()) expect(res).toBe('A') })
mapResponse should only be called on valid, non-error responses, regardless of where it's invoked.
mapResponse is sometimes called when there are errors.
No response
node_modules
bun.lockb
Yes
What version of Elysia is running?
1.1.16
What platform is your computer?
Darwin 23.4.0 arm64 arm
What steps can reproduce the bug?
.mapResponse
behaves differently depending on whether it's invoked before or after other methods. This is based on the mapResponse test hereCase 1
mapResponse
before the method handler will map the response.Case 2
mapResponse
after the request handler will not map the response (the route returns an error).Case 3
Same as case 1, but for some reason printing out the
context
will mean the response is not mapped.What is the expected behavior?
mapResponse
should only be called on valid, non-error responses, regardless of where it's invoked.What do you see instead?
mapResponse
is sometimes called when there are errors.Additional information
No response
Have you try removing the
node_modules
andbun.lockb
and try again yet?Yes