-
Notifications
You must be signed in to change notification settings - Fork 31
[bug] Incorrect Elysia.status log #206
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Description
Currently, evlog/elysia only log correct status when set.status is explicitly set as follows
const app = new Elysia()
.use(evlog())
.get("/users/:id", () => {
set.status = 418
return "I'm a teapot"
})
.listen(3000);However, set.status is a legacy, and it's recommended to use status instead
The current implementation doesn't work because it's using Elysia.afterHandle which runs immediately after the handler is run, but Elysia hasn't finalized the Response mapping process yet, so the set.status doesn't sync with an actual response status
The fix is to migrate to Elysia.afterResponse, which runs after the response is sent, so the set.status is synced with an actual response
Reproduction
The following code would log 200 instead of 418
const app = new Elysia()
.use(evlog())
.get("/users/:id", async ({ status }) => {
return status(418)
})
.listen(3000);Logs
21:13:56.775 INFO [app] GET /users/1 200 in 2ms
└─ requestId: c76f1155-55e4-4381-895e-7f67e346fbed
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working