Skip to content
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

Custom validation error message returns as string #968

Open
MollariDev opened this issue Dec 24, 2024 · 0 comments
Open

Custom validation error message returns as string #968

MollariDev opened this issue Dec 24, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@MollariDev
Copy link

What version of Elysia is running?

1.2.2

What platform is your computer?

Linux 5.15.133.1-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

import { Elysia, t } from "elysia";

const app = new Elysia()
  .post("/works", ({ body: { name } }) => ({ hello: name }), {
    body: t.Object({
      name: t.String({ minLength: 1 })
    })
  })
  .post("/bug", ({ body: { name } }) => ({ hello: name }), {
    body: t.Object({
      name: t.String({ minLength: 1, error: "bug :(" })
    })
  })
  .listen(3000);

What is the expected behavior?

Posting
{name: ""}
to the /works endpoint returns the typebox validation failed object with the content-type headers of the response application/json. I would expect the /bug endpoint to do the same except substitute my custom error message.

{
  "type": "validation",
  "on": "body",
  "summary": "Expected string length greater or equal to 1",
  "property": "/name",
  "message": "Expected string length greater or equal to 1",
  "expected": {
    "name": " "
  },
  "found": {
    "name": ""
  },
  "errors": [
    {
      "summary": "Expected string length greater or equal to 1",
      "type": 52,
      "schema": {
        "minLength": 1,
        "type": "string"
      },
      "path": "/name",
      "value": "",
      "message": "Expected string length greater or equal to 1",
      "errors": []
    }
  ]
}

What do you see instead?

Posting
{name: ""}
to the /bug endpoint it returns just the custom error message as a string without any of the other typebox validation information and the response headers are still application/json.

bug: (

Additional information

No response

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

Yes

@MollariDev MollariDev added the bug Something isn't working label Dec 24, 2024
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