Show violation details in case a ConstraintViolationException is raised (#434)
* Show violation details in case a ConstraintViolationException is raised Signed-off-by: Dominic Schabel <dominic.schabel@bosch-si.com> * Review comments added.
This commit is contained in:
committed by
Kai Zimmermann
parent
dce3263df3
commit
bc5b11d39a
@@ -11,6 +11,13 @@ package org.eclipse.hawkbit.ui.components;
|
||||
import static com.vaadin.ui.themes.ValoTheme.NOTIFICATION_CLOSABLE;
|
||||
import static com.vaadin.ui.themes.ValoTheme.NOTIFICATION_FAILURE;
|
||||
import static com.vaadin.ui.themes.ValoTheme.NOTIFICATION_SMALL;
|
||||
import static java.lang.System.lineSeparator;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
@@ -91,10 +98,29 @@ public class HawkbitUIErrorHandler extends DefaultErrorHandler {
|
||||
* @return a hawkbit error notification message
|
||||
*/
|
||||
protected HawkbitErrorNotificationMessage buildNotification(final Throwable ex) {
|
||||
|
||||
LOG.error("Error in UI: ", ex);
|
||||
|
||||
final String errorMessage = extractMessageFrom(ex);
|
||||
|
||||
final I18N i18n = SpringContextHelper.getBean(I18N.class);
|
||||
return new HawkbitErrorNotificationMessage(STYLE, i18n.get("caption.error"),
|
||||
i18n.get("message.error.temp", ex.getClass().getSimpleName()), false);
|
||||
i18n.get("message.error.temp", errorMessage), false);
|
||||
}
|
||||
|
||||
private String extractMessageFrom(final Throwable ex) {
|
||||
|
||||
if (!(ex instanceof ConstraintViolation)) {
|
||||
return ex.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
final Set<ConstraintViolation<?>> violations = ((ConstraintViolationException) ex).getConstraintViolations();
|
||||
|
||||
if (violations == null) {
|
||||
return ex.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
return violations.stream().map(violation -> violation.getPropertyPath() + " " + violation.getMessage())
|
||||
.collect(joining(lineSeparator()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user