You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the validation error response isn't structured in a way that's easily usable by the client without additional parsing.
By default I get something like this (assuming a "email", "name", and "message" field):
{
"status": "INVALID_ARGUMENT",
"error": "invalid argument: validation failed",
"context": {
"body": [
"#: validation failed",
"#/message: length must be >= 10, but got 0",
"#/name: length must be >= 3, but got 0",
"#/email: \"\" is not valid \"email\""
]
}
}
So if i want to use that in my UI to show errors on specific fields, I have to manually parse out each. Which actually wouldn't be so bad if the messages were consistent. But, for example, missing required fields get returned like this (and if there are multiple they are returned in the same message):
I'd like to return something more structured, perhaps like this:
{
"status": "INVALID_ARGUMENT",
"error": "invalid argument: validation failed",
"context": {
"errors": [
{
"field": "message",
"error": "minLength",
"message": "length must be >= 10, but got 0",
},
{
"field": "name",
"error": "minLength",
"message": "length must be >= 3, but got 0",
},
{
"field": "email",
"error": "format",
"message": "\"\" is not valid \"email\"",
},
{
"field": "requiredField1",
"error": "required",
"message": "requiredField1 is required",
},
{
"field": "requiredField2",
"error": "required",
"message": "requiredField2 is required",
}
]
}
}
Is this possible? It looks like customizing the Validator may work to some extent? Is that possible? But even doing that it seems like this wouldn't help with the required field issue, because according to this that seems to be generated by the underlying jsonschema library? Though I guess if you're customizing the Validator you could use a different library?
Has anyone been able to do anything like this? Is this possible?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Currently the validation error response isn't structured in a way that's easily usable by the client without additional parsing.
By default I get something like this (assuming a "email", "name", and "message" field):
{ "status": "INVALID_ARGUMENT", "error": "invalid argument: validation failed", "context": { "body": [ "#: validation failed", "#/message: length must be >= 10, but got 0", "#/name: length must be >= 3, but got 0", "#/email: \"\" is not valid \"email\"" ] } }So if i want to use that in my UI to show errors on specific fields, I have to manually parse out each. Which actually wouldn't be so bad if the messages were consistent. But, for example, missing required fields get returned like this (and if there are multiple they are returned in the same message):
I'd like to return something more structured, perhaps like this:
{ "status": "INVALID_ARGUMENT", "error": "invalid argument: validation failed", "context": { "errors": [ { "field": "message", "error": "minLength", "message": "length must be >= 10, but got 0", }, { "field": "name", "error": "minLength", "message": "length must be >= 3, but got 0", }, { "field": "email", "error": "format", "message": "\"\" is not valid \"email\"", }, { "field": "requiredField1", "error": "required", "message": "requiredField1 is required", }, { "field": "requiredField2", "error": "required", "message": "requiredField2 is required", } ] } }Is this possible? It looks like customizing the Validator may work to some extent? Is that possible? But even doing that it seems like this wouldn't help with the required field issue, because according to this that seems to be generated by the underlying jsonschema library? Though I guess if you're customizing the Validator you could use a different library?
Has anyone been able to do anything like this? Is this possible?
Beta Was this translation helpful? Give feedback.
All reactions