Currently when I add validators to the input type using the class-validator library and there is validation error, I get the following error message: Argument Validation Error. Which is ok, but we can provide custom message to each validator:
@IsNotEmpty({ message: "Title can't be empty" })
What about using this message to give use more info about what caused error?
ArgumentValidationError has a validationErrors propety that has all info that class-validator returns:
https://github.com/19majkel94/type-graphql/blob/68689fd848af0348b70171142da9f6bb35cb8512/src/errors/ArgumentValidationError.ts#L4
And it's returned to the client:
https://github.com/19majkel94/type-graphql/issues/258#issuecomment-466637130
@19majkel94 ah right it's deep in the errors structure that's why I've assumed that it's not there. I didn't dig deep enough. Just to get validation error I have to dig as deep as this one:
errors[0].extensions.exception.validationErrors[0].constrains.isNotEmpty
Before I've just though about displaying the first validation error that occurred in the form of snackbar. But having all the validation errors I can actually display them next to the form fields which is nice.
Thanks!
I have validations on my Args and none of the messages are passing through. :(
{
"errors": [
{
"message": "Argument Validation Error",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"signup"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"validationErrors": {},
"stacktrace": [
"Error: Argument Validation Error",
...
}
}
}
],
"data": null
}
@reggi show your code
Most helpful comment
@19majkel94 ah right it's deep in the errors structure that's why I've assumed that it's not there. I didn't dig deep enough. Just to get validation error I have to dig as deep as this one:
errors[0].extensions.exception.validationErrors[0].constrains.isNotEmptyBefore I've just though about displaying the first validation error that occurred in the form of snackbar. But having all the validation errors I can actually display them next to the form fields which is nice.
Thanks!