diff --git a/udf-starter-core/src/main/java/org/itkk/udf/core/exception/handle/ExceptionHandle.java b/udf-starter-core/src/main/java/org/itkk/udf/core/exception/handle/ExceptionHandle.java index 10764f1..0adcbf7 100644 --- a/udf-starter-core/src/main/java/org/itkk/udf/core/exception/handle/ExceptionHandle.java +++ b/udf-starter-core/src/main/java/org/itkk/udf/core/exception/handle/ExceptionHandle.java @@ -1,5 +1,6 @@ package org.itkk.udf.core.exception.handle; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -11,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.client.RestClientResponseException; @@ -84,6 +86,13 @@ public class ExceptionHandle extends ResponseEntityExceptionHandler { } catch (IOException e) { throw new SystemRuntimeException(e); } + } else if (ex instanceof MethodArgumentNotValidException) { //参数校验异常 + MethodArgumentNotValidException methodArgumentNotValidException = (MethodArgumentNotValidException) ex; + try { + errorResult.setMessage(objectMapper.writeValueAsString(methodArgumentNotValidException.getBindingResult().getAllErrors())); + } catch (JsonProcessingException e) { + throw new SystemRuntimeException(e); + } } log.error(ex.getClass().getName(), ex); return super.handleExceptionInternal(ex, new RestResponse<>(localHttpStatus, errorResult), headers, localHttpStatus, request);