Skip to content

Commit 2f553cb

Browse files
committed
🔧 fix: trace with route
1 parent 84e0190 commit 2f553cb

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# 1.2.24 - 2 Mar 2025
22
Bug fix:
33
- 200 object response is not inferring type in type-level
4-
-
4+
- [#1091](https://github.com/elysiajs/elysia/issues/1091) route is not defined when using trace
55

66
# 1.2.23 - 25 Feb 2025
77
Bug fix:

example/a.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ const app = new Elysia().get(
1010
}
1111
},
1212
{
13-
response: {
14-
200: t.Object({
15-
name: t.String()
16-
})
17-
}
13+
response: t.Object({
14+
name: t.String()
15+
})
1816
}
1917
)
2018

src/compose.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ export const composeHandler = ({
10131013
? `,${adapter.mapResponseContext}`
10141014
: ''
10151015

1016-
if (inference.route) fnLiteral += `c.route=\`${path}\`\n`
1016+
if (hasTrace || inference.route) fnLiteral += `c.route=\`${path}\`\n`
10171017

10181018
const parseReporter = report('parse', {
10191019
total: hooks.parse?.length

test/tracer/trace.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,4 +422,25 @@ describe('trace', () => {
422422

423423
expect(isCalled).toBeTrue()
424424
})
425+
426+
it('report route when using trace', async () => {
427+
let route: string | undefined
428+
429+
const app = new Elysia()
430+
.trace(({ onHandle, context }) => {
431+
onHandle(({ onStop }) => {
432+
onStop(({ error }) => {
433+
route = context.route
434+
expect(error).toBeInstanceOf(Error)
435+
})
436+
})
437+
})
438+
.get('/id/:id', () => {
439+
throw new Error('A')
440+
})
441+
442+
await app.handle(req('/id/1'))
443+
444+
expect(route).toBe('/id/:id')
445+
})
425446
})

0 commit comments

Comments
 (0)