jisti-meet服务开启
This commit is contained in:
@@ -33,6 +33,11 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
||||
@@ -2,8 +2,11 @@ package org.xyzh.common.exception.handler;
|
||||
|
||||
import jakarta.validation.ConstraintViolation;
|
||||
import jakarta.validation.ConstraintViolationException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.authorization.AuthorizationDeniedException;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
@@ -26,17 +29,16 @@ import java.util.stream.Collectors;
|
||||
* @copyright yslg
|
||||
* @since 2025-12-17
|
||||
*/
|
||||
@Slf4j
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||
/**
|
||||
* 业务异常
|
||||
*/
|
||||
@ExceptionHandler(BusinessException.class)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResultDomain<?> handleBusinessException(BusinessException e) {
|
||||
log.warn("业务异常: {}", e.getMessage());
|
||||
logger.warn("业务异常: {}", e.getMessage());
|
||||
return ResultDomain.failure(e.getCode(), e.getMessage());
|
||||
}
|
||||
|
||||
@@ -49,7 +51,7 @@ public class GlobalExceptionHandler {
|
||||
String message = e.getBindingResult().getFieldErrors().stream()
|
||||
.map(FieldError::getDefaultMessage)
|
||||
.collect(Collectors.joining("; "));
|
||||
log.warn("参数校验失败: {}", message);
|
||||
logger.warn("参数校验失败: {}", message);
|
||||
return ResultDomain.failure(HttpStatus.BAD_REQUEST.value(), message);
|
||||
}
|
||||
|
||||
@@ -63,7 +65,7 @@ public class GlobalExceptionHandler {
|
||||
String message = violations.stream()
|
||||
.map(ConstraintViolation::getMessage)
|
||||
.collect(Collectors.joining("; "));
|
||||
log.warn("参数校验失败: {}", message);
|
||||
logger.warn("参数校验失败: {}", message);
|
||||
return ResultDomain.failure(HttpStatus.BAD_REQUEST.value(), message);
|
||||
}
|
||||
|
||||
@@ -76,7 +78,7 @@ public class GlobalExceptionHandler {
|
||||
String message = e.getFieldErrors().stream()
|
||||
.map(FieldError::getDefaultMessage)
|
||||
.collect(Collectors.joining("; "));
|
||||
log.warn("参数绑定失败: {}", message);
|
||||
logger.warn("参数绑定失败: {}", message);
|
||||
return ResultDomain.failure(HttpStatus.BAD_REQUEST.value(), message);
|
||||
}
|
||||
|
||||
@@ -87,7 +89,7 @@ public class GlobalExceptionHandler {
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResultDomain<?> handleMissingServletRequestParameterException(MissingServletRequestParameterException e) {
|
||||
String message = "缺少必要参数: " + e.getParameterName();
|
||||
log.warn(message);
|
||||
logger.warn(message);
|
||||
return ResultDomain.failure(HttpStatus.BAD_REQUEST.value(), message);
|
||||
}
|
||||
|
||||
@@ -98,7 +100,7 @@ public class GlobalExceptionHandler {
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResultDomain<?> handleMissingServletRequestPartException(MissingServletRequestPartException e) {
|
||||
String message = "缺少必要参数: " + e.getRequestPartName();
|
||||
log.warn(message);
|
||||
logger.warn(message);
|
||||
return ResultDomain.failure(HttpStatus.BAD_REQUEST.value(), message);
|
||||
}
|
||||
|
||||
@@ -108,17 +110,27 @@ public class GlobalExceptionHandler {
|
||||
@ExceptionHandler(MaxUploadSizeExceededException.class)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResultDomain<?> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e) {
|
||||
log.warn("文件上传大小超限: {}", e.getMessage());
|
||||
logger.warn("文件上传大小超限: {}", e.getMessage());
|
||||
return ResultDomain.failure(HttpStatus.BAD_REQUEST.value(), "上传文件大小超过限制");
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限不足异常
|
||||
*/
|
||||
@ExceptionHandler(AuthorizationDeniedException.class)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResultDomain<?> handleAuthorizationDeniedException(AuthorizationDeniedException e) {
|
||||
logger.warn("权限不足: {}", e.getMessage());
|
||||
return ResultDomain.failure(HttpStatus.FORBIDDEN.value(), "权限不足");
|
||||
}
|
||||
|
||||
/**
|
||||
* 其他未捕获异常
|
||||
*/
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResultDomain<?> handleException(Exception e) {
|
||||
log.error("系统异常: ", e);
|
||||
logger.error("系统异常: ", e);
|
||||
return ResultDomain.failure(HttpStatus.INTERNAL_SERVER_ERROR.value(), "系统异常,请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user