06534673 by chentao

no message

1 parent 4ef82288
......@@ -25,6 +25,7 @@ import org.springframework.web.method.annotation.MethodArgumentTypeMismatchExcep
import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.util.Objects;
/**
* 全局异常处理器
......@@ -186,8 +187,14 @@ public class GlobalExceptionHandler {
@ExceptionHandler(MethodArgumentNotValidException.class)
public R<Void> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
log.error(e.getMessage());
String message = e.getBindingResult().getFieldError().getDefaultMessage();
return R.fail(message);
if(Objects.nonNull(e.getBindingResult().getFieldError())) {
String message = e.getBindingResult().getFieldError().getDefaultMessage();
return R.fail(message);
}
else{
String message = e.getBindingResult().getGlobalError().getDefaultMessage();
return R.fail(message);
}
}
/**
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!