refactor: 优化注释和代码优化
This commit is contained in:
@@ -22,18 +22,19 @@ import org.springframework.web.servlet.NoHandlerFoundException;
|
|||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
import jakarta.validation.ConstraintViolation;
|
import jakarta.validation.ConstraintViolation;
|
||||||
import jakarta.validation.ConstraintViolationException;
|
import jakarta.validation.ConstraintViolationException;
|
||||||
|
|
||||||
import java.sql.SQLSyntaxErrorException;
|
import java.sql.SQLSyntaxErrorException;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局系统异常处理
|
* 全局系统异常处理器
|
||||||
*
|
* <p>
|
||||||
* 调整异常处理的HTTP状态码,丰富异常处理类型
|
* 调整异常处理的HTTP状态码,丰富异常处理类型
|
||||||
*
|
*
|
||||||
* @author Gadfly
|
* @author Gadfly
|
||||||
* @date 2020-02-25 13:54
|
* @since 2020-02-25 13:54
|
||||||
**/
|
**/
|
||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -173,7 +174,7 @@ public class GlobalExceptionHandler {
|
|||||||
@ExceptionHandler(BusinessException.class)
|
@ExceptionHandler(BusinessException.class)
|
||||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
public <T> Result<T> handleBizException(BusinessException e) {
|
public <T> Result<T> handleBizException(BusinessException e) {
|
||||||
log.error("biz exception,{}", e.getMessage());
|
log.error("biz exception: {}", e.getMessage());
|
||||||
if (e.getResultCode() != null) {
|
if (e.getResultCode() != null) {
|
||||||
return Result.failed(e.getResultCode());
|
return Result.failed(e.getResultCode());
|
||||||
}
|
}
|
||||||
@@ -183,7 +184,7 @@ public class GlobalExceptionHandler {
|
|||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
public <T> Result<T> handleException(Exception e) {
|
public <T> Result<T> handleException(Exception e) {
|
||||||
log.error("unknown exception, {}", e.getMessage());
|
log.error("unknown exception: {}", e.getMessage());
|
||||||
return Result.failed(e.getLocalizedMessage());
|
return Result.failed(e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,7 +203,7 @@ public class GlobalExceptionHandler {
|
|||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
String matchString = matcher.group();
|
String matchString = matcher.group();
|
||||||
matchString = matchString.replace("[", "").replace("]", "");
|
matchString = matchString.replace("[", "").replace("]", "");
|
||||||
matchString = matchString.replaceAll("\\\"", "") + "字段类型错误";
|
matchString = "%s字段类型错误".formatted(matchString.replaceAll("\\\"", ""));
|
||||||
group += matchString;
|
group += matchString;
|
||||||
}
|
}
|
||||||
return group;
|
return group;
|
||||||
|
|||||||
Reference in New Issue
Block a user