ConstraintViolationException can contain mulitple violation messages
Signed-off-by: Melanie Retter <melanie.retter@bosch-si.com>
This commit is contained in:
@@ -12,8 +12,8 @@ import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
|
||||
/**
|
||||
* the {@link ConstraintViolationException} is thrown when an entity is
|
||||
* tried to be saved which has constraint violations
|
||||
* the {@link ConstraintViolationException} is thrown when an entity is tried to
|
||||
* be saved which has constraint violations
|
||||
*
|
||||
*/
|
||||
public class ConstraintViolationException extends AbstractServerRtException {
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.ConstraintViolation;
|
||||
@@ -141,16 +142,16 @@ public class ResponseExceptionHandler {
|
||||
final Exception ex) {
|
||||
logRequest(request, ex);
|
||||
|
||||
final ExceptionInfo response = null;
|
||||
final Set<ConstraintViolation<?>> violations = ((ConstraintViolationException) ex).getConstraintViolations();
|
||||
|
||||
final List<String> messages = new ArrayList<>();
|
||||
violations.stream()
|
||||
.forEach(violation -> messages.add(violation.getPropertyPath() + " " + violation.getMessage() + ". "));
|
||||
.forEach(violation -> messages.add(violation.getPropertyPath() + " " + violation.getMessage() + "."));
|
||||
|
||||
final ExceptionInfo response = createExceptionInfo(
|
||||
new org.eclipse.hawkbit.repository.exception.ConstraintViolationException(
|
||||
messages.stream().collect(Collectors.joining(" "))));
|
||||
|
||||
// response = createExceptionInfo(new
|
||||
// org.eclipse.hawkbit.repository.exception.ConstraintViolationException(
|
||||
// messages.forEach(StringBuilder::append(this))));
|
||||
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user