From 612ea6cea8052145a0b8b2b6c6793c4405a698df Mon Sep 17 00:00:00 2001 From: haoxr <1490493387@qq.com> Date: Wed, 10 May 2023 06:42:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E5=92=8C=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/GlobalExceptionHandler.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/youlai/system/common/exception/GlobalExceptionHandler.java b/src/main/java/com/youlai/system/common/exception/GlobalExceptionHandler.java index 52e47d16..5091b681 100644 --- a/src/main/java/com/youlai/system/common/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/youlai/system/common/exception/GlobalExceptionHandler.java @@ -22,18 +22,19 @@ import org.springframework.web.servlet.NoHandlerFoundException; import jakarta.servlet.ServletException; import jakarta.validation.ConstraintViolation; import jakarta.validation.ConstraintViolationException; + import java.sql.SQLSyntaxErrorException; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; /** - * 全局系统异常处理 - * + * 全局系统异常处理器 + *

* 调整异常处理的HTTP状态码,丰富异常处理类型 * * @author Gadfly - * @date 2020-02-25 13:54 + * @since 2020-02-25 13:54 **/ @RestControllerAdvice @Slf4j @@ -152,7 +153,7 @@ public class GlobalExceptionHandler { @ExceptionHandler(BadSqlGrammarException.class) @ResponseStatus(HttpStatus.FORBIDDEN) - public Result handleBadSqlGrammarException(BadSqlGrammarException e) { + public Result handleBadSqlGrammarException(BadSqlGrammarException e) { log.error(e.getMessage(), e); String errorMsg = e.getMessage(); if (StrUtil.isNotBlank(errorMsg) && errorMsg.contains("denied to user")) { @@ -173,7 +174,7 @@ public class GlobalExceptionHandler { @ExceptionHandler(BusinessException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public Result handleBizException(BusinessException e) { - log.error("biz exception,{}", e.getMessage()); + log.error("biz exception: {}", e.getMessage()); if (e.getResultCode() != null) { return Result.failed(e.getResultCode()); } @@ -183,7 +184,7 @@ public class GlobalExceptionHandler { @ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public Result handleException(Exception e) { - log.error("unknown exception, {}", e.getMessage()); + log.error("unknown exception: {}", e.getMessage()); return Result.failed(e.getLocalizedMessage()); } @@ -202,7 +203,7 @@ public class GlobalExceptionHandler { if (matcher.find()) { String matchString = matcher.group(); matchString = matchString.replace("[", "").replace("]", ""); - matchString = matchString.replaceAll("\\\"", "") + "字段类型错误"; + matchString = "%s字段类型错误".formatted(matchString.replaceAll("\\\"", "")); group += matchString; } return group;