Example usage for org.springframework.data.rest.core RepositoryConstraintViolationException getErrors

List of usage examples for org.springframework.data.rest.core RepositoryConstraintViolationException getErrors

Introduction

In this page you can find the example usage for org.springframework.data.rest.core RepositoryConstraintViolationException getErrors.

Prototype

public Errors getErrors() 

Source Link

Usage

From source file:org.springframework.data.rest.webmvc.support.RepositoryConstraintViolationExceptionMessage.java

/**
 * Creates a new {@link RepositoryConstraintViolationExceptionMessage} for the given
 * {@link RepositoryConstraintViolationException} and {@link MessageSourceAccessor}.
 * //from w ww. ja  va2  s . c o m
 * @param exception must not be {@literal null}.
 * @param accessor must not be {@literal null}.
 */
public RepositoryConstraintViolationExceptionMessage(RepositoryConstraintViolationException exception,
        MessageSourceAccessor accessor) {

    Assert.notNull(exception, "RepositoryConstraintViolationException must not be null!");
    Assert.notNull(accessor, "MessageSourceAccessor must not be null!");

    for (FieldError fieldError : exception.getErrors().getFieldErrors()) {
        this.errors.add(ValidationError.of(fieldError.getObjectName(), fieldError.getField(),
                fieldError.getRejectedValue(), accessor.getMessage(fieldError)));
    }
}