Skip to content

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

@plbin97

Description

@plbin97

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions