-
-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proper way to access response code in onResponse
hook?
#88
Comments
@SaltyAom The problem persists. Failed hooks validation is not the only case where Here is a minimal reproduction example: import { Elysia } from "elysia";
new Elysia()
.onResponse(({ set }) => {
console.log(`Response code: ${set.status}`);
})
.get("/", () => {
return new Response("Not Found", {
status: 404,
});
})
.listen(3000); Performing a
but the code prints:
The issue is that (tested on Elysia 0.6.19) |
@SaltyAom can confirm on 0.6.24. |
I want to use the
onResponse
hook to print a log message every time a response is generated. Right now I am reading the value ofset.status
to determine the HTTP status code of the response. However in cases where Elysia responds early due to an error, the value ofset.status
is incorrect. For example if body validation fails, the server responds to the client with code 400 but the value ofset.status
is 500.Is this the wrong way of determining info about the response? I did not see any other way in the docs or function signature. From what I can tell, the response itself isn't actually accessible in the
onResponse
hook.The text was updated successfully, but these errors were encountered: