|
|
@@ -14,6 +14,7 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.validation.BindException;
|
|
|
+import org.springframework.validation.FieldError;
|
|
|
import org.springframework.validation.ObjectError;
|
|
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
@@ -102,12 +103,16 @@ public class GlobalExceptionHandler {
|
|
|
* @return
|
|
|
*/
|
|
|
@ExceptionHandler(value = {BindException.class, ValidationException.class})
|
|
|
- public R handleValidatedException(Exception e) {
|
|
|
+ public R<?> handleValidatedException(Exception e) {
|
|
|
String message = "";
|
|
|
if (e instanceof MethodArgumentNotValidException) {
|
|
|
- message = ((MethodArgumentNotValidException) e).getBindingResult().getAllErrors().stream()
|
|
|
- .map(ObjectError::getDefaultMessage)
|
|
|
- .collect(Collectors.joining("; "));
|
|
|
+// message = ((MethodArgumentNotValidException) e).getBindingResult().getAllErrors().stream()
|
|
|
+// .map(ObjectError::getDefaultMessage)
|
|
|
+// .collect(Collectors.joining("; "));
|
|
|
+
|
|
|
+ FieldError firstError = ((MethodArgumentNotValidException) e).getBindingResult().getFieldErrors().get(0);
|
|
|
+ return R.failed(HttpStatus.BAD_REQUEST.value(),firstError.getDefaultMessage());
|
|
|
+
|
|
|
} else if (e instanceof ConstraintViolationException) {
|
|
|
message = ((ConstraintViolationException) e).getConstraintViolations().stream()
|
|
|
.map(ConstraintViolation::getMessage)
|