spring-projects / spring-projects/spring-data-rest
Add ability to customize validation error output [DATAREST-284]
Open
@odrotbohm is already working on this.
Since Dec 31, 2020.
type: enhancement
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Aaron Loes opened DATAREST-284 and commented
For our needs, we want more information in the validation errors returned in the response. There is currently no way to customize the marshaling of the the validation errors other than to override the implementation of RepositoryConstraintViolationExceptionMessage.
What is provided:
{
"errors" : [ {
"entity" : "<persistent entity>",
"message" : "<internationalized message>",
"invalidValue" : "<provided parameter value>",
"property" : "<persistent entity property in violation>"
},
...
]
}
What is desired:
{
"errors" : [ {
"entity" : "<persistent entity>",
"message" : "<internationalized message>",
"invalidValue" : "<provided parameter value>",
"property" : "<persistent entity property in violation>",
"constraint" : "<the contstraint that was violated>"
"contraint-params" : {
"<param-1-name>" : "<param-1-value>",
"<param-2-name>" : "<param-2-value>",
"<param-3-name>" : "<param-3-value>",
...
}
},
...
]
}
Example:
{
"errors" : [ {
"message" : "The value [SuperLongCowName] for property [name] of entity [Cow] is limited to a maximum value of [15]",
"entity" : "Cow",
"property" : "name",
"invalidValue" : "SuperLongCowName",
"constraint" : "maxLength"
"contraint-params" : {
"valueCurrentLength" : "16",
"propertyAllowedMaxLength" : "15"
}
},{
"message" : "The value [This cow has a super long name for a cow dude!] for property [description] of entity [Cow] must not contain exclaimation points",
"entity" : "Cow",
"property" : "description",
"invalidValue" : "This cow has a super long name for a cow dude!",
"constraint" : "matches"
"contraint-params" : {
"pattern" : "[^!]"
}
}]
}
3 votes, 5 watchers
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.