spring-projects / spring-projects/spring-data-rest
using validators in spring-data-rest returns http 500 instead of 400 [DATAREST-260]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
chris opened DATAREST-260 and commented
successful (in)validated data posted results in http 500 instead of 400, from looking at the source for ValidationExceptionHandler it should return constraint violations as 400.
I have to override the validatingRepositoryEventListener bean in RepositoryRestMvcConfiguration and add each of the event validations into the listeners as follows;
@Configuration
public class RestExporterRestConfig extends RepositoryRestMvcConfiguration {
@Bean
public Validator validator() {
return new LocalValidatorFactoryBean();
}
@Bean
@Override
public ValidatingRepositoryEventListener validatingRepositoryEventListener() {
ValidatingRepositoryEventListener listener = new ValidatingRepositoryEventListener();
configureValidatingRepositoryEventListener(listener);
listener.addValidator("afterCreate", validator());
listener.addValidator("beforeCreate", validator());
return listener;
}
}
Affects: 2.0 GA (Codd)
Reference URL: http://stackoverflow.com/questions/22029727/using-validators-in-spring-data-rest-returns-http-500-instead-of-400
5 votes, 9 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.