Returning `status(404, undefined)` actually sends a 422 to the client
What version of Elysia is running?
What platform is your computer?
Linux
What environment are you using
1.2.22
Are you using dynamic mode?
no
What steps can reproduce the bug?
- Define the return schema as
response: {
200: t.Object({
id: t.String(),
}),
404: t.Void(),
500: t.String(),
},
- Return an error
return status(404, undefined);
What is the expected behavior?
Client should receive 404 error.
What do you see instead?
Client receives 422 error.
Additional information
No response
Have you try removing the node_modules and bun.lockb and try again yet?
No response
Did you specify a body scheme?
Body will automatically be validated by elysia on request. If request Body does not match your defined schema, it will respond inline with 422 validation failed.
There is a body schema, and it passes just fine: the handler's inner code runs. The bug is definitely linked to the status(404, undefined) and its definition as t.Void() rather than t.String()
I would recommend against using Void. Because void cannot be matched with undefined.
Its just that the response does allow to be undefined, but I guess the internal check from Elysia is unable to check undefined against void. I think the response is validated too.
Try null instead.
t.Null() --> status(404, null)
This might be the reason for your Issue:
⚠️ This is type is cannot be expressed with Json. Do not use if publishing types for other languages to consume. https://sinclairzx81.github.io/typebox/#/docs/type/void