use of cn.taketoday.validation.ObjectError in project today-framework by TAKETODAY.
the class BindValidationFailureAnalyzer method getBindValidationExceptionDetails.
private ExceptionDetails getBindValidationExceptionDetails(Throwable rootFailure) {
BindValidationException validationException = findCause(rootFailure, BindValidationException.class);
if (validationException != null) {
BindException target = findCause(rootFailure, BindException.class);
List<ObjectError> errors = validationException.getValidationErrors().getAllErrors();
return new ExceptionDetails(errors, target, validationException);
}
cn.taketoday.validation.BindException bindException = findCause(rootFailure, cn.taketoday.validation.BindException.class);
if (bindException != null) {
List<ObjectError> errors = bindException.getAllErrors();
return new ExceptionDetails(errors, bindException.getTarget(), bindException);
}
return null;
}
use of cn.taketoday.validation.ObjectError in project today-framework by TAKETODAY.
the class DefaultErrorAttributesTests method withoutBindingErrors.
@Test
void withoutBindingErrors() {
BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a", "b"), "objectName");
bindingResult.addError(new ObjectError("c", "d"));
Exception ex = new BindException(bindingResult);
testBindingResult(bindingResult, ex, ErrorAttributeOptions.defaults());
}
use of cn.taketoday.validation.ObjectError in project today-framework by TAKETODAY.
the class MethodArgumentNotValidException method getMessage.
@Override
public String getMessage() {
StringBuilder sb = new StringBuilder("Validation failed for argument [").append(this.parameter.getParameterIndex()).append("] in ").append(this.parameter.getExecutable().toGenericString());
BindingResult bindingResult = getBindingResult();
if (bindingResult.getErrorCount() > 1) {
sb.append(" with ").append(bindingResult.getErrorCount()).append(" errors");
}
sb.append(": ");
for (ObjectError error : bindingResult.getAllErrors()) {
sb.append('[').append(error).append("] ");
}
return sb.toString();
}
use of cn.taketoday.validation.ObjectError in project today-framework by TAKETODAY.
the class DefaultErrorAttributesTests method withBindingErrors.
@Test
void withBindingErrors() {
BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a", "b"), "objectName");
bindingResult.addError(new ObjectError("c", "d"));
Exception ex = new BindException(bindingResult);
testBindingResult(bindingResult, ex, ErrorAttributeOptions.of(Include.MESSAGE, Include.BINDING_ERRORS));
}
use of cn.taketoday.validation.ObjectError in project today-framework by TAKETODAY.
the class DefaultErrorAttributesTests method withMethodArgumentNotValidExceptionBindingErrors.
@Test
void withMethodArgumentNotValidExceptionBindingErrors() {
Method method = ReflectionUtils.findMethod(String.class, "substring", int.class);
MethodParameter parameter = new MethodParameter(method, 0);
BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a", "b"), "objectName");
bindingResult.addError(new ObjectError("c", "d"));
Exception ex = new MethodArgumentNotValidException(parameter, bindingResult);
testBindingResult(bindingResult, ex, ErrorAttributeOptions.of(Include.MESSAGE, Include.BINDING_ERRORS));
}
Aggregations