Skip to content

No 400 bad request when post request json format is invalid #37

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

Open
plbin97 opened this issue Apr 15, 2025 · 0 comments
Open

No 400 bad request when post request json format is invalid #37

plbin97 opened this issue Apr 15, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@plbin97
Copy link

plbin97 commented Apr 15, 2025

What version of Elysia is running?

1.2.25

What version of Node Adapter are you using?

20.12.2

What platform is your computer?

MacOS x86_64

What steps can reproduce the bug?

Create an Elysia instance that handle post request

export const signInRoute = new Elysia().post(
  '/sign-in',
  ({ body }) => {
    return body
  },
  {
    body: t.Object({
      phoneNumber: t.Nullable(t.String()),
      email: t.Nullable(t.String()),
      password: t.String(),
    }),
  },
)

Send request in postman with wrong JSON format

Image

What is the expected behavior?

Response a 400 bad request

What do you see instead?

Backend down:

Image

With console:

Server is running on port 3030
undefined:3
    "email": null,
    ^

SyntaxError: Expected ',' or '}' after property value in JSON at position 31
    at JSON.parse (<anonymous>)
    at IncomingMessage.eval (eval at composeHandler (/Users/linbin/WebstormProjects/badminton-rank-backend/node_modules/elysia/dist/cjs/compose.js:1231:12), <anonymous>:27:14)
    at IncomingMessage.emit (node:events:518:28)
    at endReadableNT (node:internal/streams/readable:1696:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v20.12.2

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

Yes but not works

@plbin97 plbin97 added the bug Something isn't working label Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant