elysia icon indicating copy to clipboard operation
elysia copied to clipboard

Returning `status(404, undefined)` actually sends a 422 to the client

Open aryzing opened this issue 7 months ago • 3 comments

What version of Elysia is running?

[email protected]

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?

  1. Define the return schema as
response: {
  200: t.Object({
    id: t.String(),
  }),
  404: t.Void(),
  500: t.String(),
},
  1. 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

aryzing avatar Sep 10 '25 12:09 aryzing

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.

peterlustig78 avatar Sep 11 '25 12:09 peterlustig78

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()

aryzing avatar Sep 11 '25 13:09 aryzing

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

peterlustig78 avatar Sep 15 '25 10:09 peterlustig78