use of org.springframework.boot.autoconfigure.web.DefaultErrorAttributes in project spring-boot-jpa by ssherwood.
the class BootJpaApplication method errorAttributes.
/**
* Customized ErrorAttribute bean.
* We really need to find a cleaner way of handling these error messages.
*
* @return customized ErrorAttributes
*/
@Bean
public ErrorAttributes errorAttributes() {
return new DefaultErrorAttributes() {
@Override
public Map<String, Object> getErrorAttributes(final RequestAttributes requestAttributes, final boolean includeStackTrace) {
Map<String, Object> attributes = super.getErrorAttributes(requestAttributes, includeStackTrace);
Throwable error = getError(requestAttributes);
if (error instanceof MethodArgumentNotValidException) {
MethodArgumentNotValidException ex = ((MethodArgumentNotValidException) error);
attributes.put("errors", ex.getMessage());
}
return attributes;
}
};
}
Aggregations