mirror of
https://gitee.com/wangkang/udf.git
synced 2026-10-27 01:53:42 +00:00
添加参数校验异常处理
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user