mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
取消板件自动写入,bug1255,1225
This commit is contained in:
+21
@@ -11,6 +11,7 @@ import com.cf.imes.framework.common.util.json.JsonUtils;
|
||||
import com.cf.imes.framework.common.util.servlet.ServletUtils;
|
||||
import com.cf.imes.module.infra.api.logger.ApiErrorLogApi;
|
||||
import com.cf.imes.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
|
||||
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
@@ -31,9 +32,12 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import javax.validation.ValidationException;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.*;
|
||||
|
||||
@@ -213,6 +217,23 @@ public class GlobalExceptionHandler {
|
||||
@ExceptionHandler(value = HttpMessageNotReadableException.class)
|
||||
public CommonResult httpMessageNotReadableExceptionHandler(HttpServletRequest req, HttpMessageNotReadableException ex) {
|
||||
log.warn("[httpMessageNotReadableExceptionHandler]", ex);
|
||||
|
||||
Throwable rootCause = ex.getRootCause();
|
||||
// 无效格式异常处理。
|
||||
if (rootCause instanceof MismatchedInputException) {
|
||||
return CommonResult.error(BAD_REQUEST.getCode(), "参数格式异常无法解读,请按照对应格式上传");
|
||||
}
|
||||
// 文件格式错误处理
|
||||
if (rootCause instanceof IOException ) {
|
||||
// 使用正则提取数值
|
||||
Pattern pattern = Pattern.compile("Numeric value \\((\\d+)\\) out of range");
|
||||
Matcher matcher = pattern.matcher(rootCause.getMessage());
|
||||
if (matcher.find()) {
|
||||
String invalidValue = matcher.group(1);
|
||||
return CommonResult.error(BAD_REQUEST.getCode(), String.format("参数校验失败:'%s' 超出范围", invalidValue));
|
||||
}
|
||||
}
|
||||
|
||||
return CommonResult.error(BAD_REQUEST.getCode(), "请求参数不合法");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user