数值长度限制提示

This commit is contained in:
lym
2025-02-21 16:35:54 +08:00
parent 17971a98dd
commit f03117fe4d
3 changed files with 16 additions and 39 deletions
@@ -11,7 +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 com.fasterxml.jackson.databind.exc.InvalidFormatException;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DuplicateKeyException;
@@ -220,11 +220,12 @@ public class GlobalExceptionHandler {
Throwable rootCause = ex.getRootCause();
// 无效格式异常处理。
if (rootCause instanceof MismatchedInputException) {
return CommonResult.error(BAD_REQUEST.getCode(), "参数格式异常无法解读,请按照对应格式上传");
if (rootCause instanceof InvalidFormatException) { // MismatchedInputException
InvalidFormatException e = (InvalidFormatException) rootCause;
return CommonResult.error(BAD_REQUEST.getCode(), String.format("参数校验失败:'%s' 格式出错", e.getValue()));
}
// 文件格式错误处理
if (rootCause instanceof IOException ) {
if (rootCause instanceof IOException) {
// 使用正则提取数值
Pattern pattern = Pattern.compile("Numeric value \\((\\d+)\\) out of range");
Matcher matcher = pattern.matcher(rootCause.getMessage());