FOSRestBundle: Detailed form errors
At the moment the form errors look something like:
{
"code": 400,
"message": "Validation Failed",
"errors": {
"children": {
"username": {
"errors": [
"This value should not be blank."
]
}
}
}
}
I would like to have both error message and error code for each validated form field, so the json would look like this example below http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#errors
{
"code" : 1024,
"message" : "Validation Failed",
"errors" : [
{
"code" : 5432,
"field" : "first_name",
"message" : "First name cannot have fancy characters"
},
{
"code" : 5622,
"field" : "password",
"message" : "Password cannot be blank"
}
]
}
Is it possible to obtain this with Symfony? Is it possible to associate an error code to a validation constraint? Or do you see any other solution?
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 1
- Comments: 22 (11 by maintainers)
@eXtreme
I had similar issue and solved it with
ExceptionWrapperHandler:In my
ControllerI simply returnFormif it’s not valid:Example result:
@lucascourot no, I don’t know. I never tried to customize the serialization of errors to add such error code, so I don’t have a solution for you
For mobile application form errors is a big trouble, because have a different formats (hash or array) 😦