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

error response when using class-validator is incorrect #1622

Closed
sincraianul opened this issue Mar 8, 2019 · 3 comments

Comments

@sincraianul
Copy link
Contributor

commented Mar 8, 2019

I'm submitting a...


[x] Regression 
[ ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

If you follow the example in the validation section of the docs and use class-validator to annotate class members, the response from the server consists only of the errors array:

[
  {
    "target": {},
    "property": "email",
    "children": [],
    "constraints": {
      "isEmail": "email must be an email"
    }
  }
]

Expected behavior

Server response should be:

{
  "statusCode": 400,
  "error": "Bad Request",
  "message": [
    {
      "target": {},
      "property": "email",
      "children": [],
      "constraints": {
        "isEmail": "email must be an email"
      }
    }
  ]
}

Minimal reproduction of the problem with instructions

Just follow the instructions in the docs.

Environment


Nest version: 5.7.3

Suggested fix

This issue occurs due to the changes brought by #1344. I can PR the behaviour and add an additional detection for isObject to exclude objects that are arrays.

@sincraianul sincraianul changed the title response when using class-validator is incorrect error response when using class-validator is incorrect Mar 8, 2019

@kamilmysliwiec

This comment has been minimized.

Copy link
Member

commented Mar 8, 2019

I can PR the behaviour and add an additional detection for isObject to exclude objects that are arrays.

Sounds perfect :) Thanks!

@sincraianul

This comment has been minimized.

Copy link
Contributor Author

commented Mar 8, 2019

fixed by #1623

@kamilmysliwiec

This comment has been minimized.

Copy link
Member

commented Mar 9, 2019

Published as 5.7.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.