doum
2026-06-16 77094dd01f0c6ff59b4fb4fa1105addf34b2398c
server/system_service/src/main/java/com/doumee/config/handler/GlobalExceptionHandler.java
ÎļþÃû´Ó server/visits/dmvisit_service/src/main/java/com/doumee/config/handler/GlobalExceptionHandler.java ÐÞ¸Ä
@@ -6,6 +6,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
@@ -17,34 +18,23 @@
/**
 * å…¨å±€å¼‚常处理
 * @author doumee
 * @date 2023/03/21 14:49
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    /**
     * ä¸šåŠ¡å¼‚å¸¸å¤„ç†
     */
    @ExceptionHandler(BusinessException.class)
    public <T> ApiResponse<T> handleBusinessException (BusinessException e) {
        log.error(e.getMessage(), e);
        log.warn("BusinessException: {}", e.getMessage());
        return ApiResponse.failed(e.getCode(), e.getMessage());
    }
    /**
     * æ— æƒé™å¼‚常处理
     */
    @ExceptionHandler(UnauthorizedException.class)
    public <T> ApiResponse<T> handleUnauthorizedException (UnauthorizedException e) {
        log.error(e.getMessage(), e);
        return ApiResponse.failed("没有操作权限");
    }
    /**
     * å‚数验证未通过异常处理
     */
    @ExceptionHandler(MethodArgumentNotValidException.class)
    public <T> ApiResponse<T> handleMethodArgumentNotValidException (MethodArgumentNotValidException e) {
        log.error(e.getMessage(), e);
@@ -56,9 +46,12 @@
        return ApiResponse.failed(ResponseStatus.BAD_REQUEST.getCode(), StringUtils.join(errors));
    }
    /**
     * å…¶å®ƒå¼‚常处理
     */
    @ExceptionHandler(HttpMessageNotReadableException.class)
    public <T> ApiResponse<T> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
        log.error(e.getMessage(), e);
        return ApiResponse.failed(ResponseStatus.BAD_REQUEST.getCode(), "请求参数格式错误");
    }
    @ExceptionHandler(Exception.class)
    public <T> ApiResponse<T> handleException (Exception e) {
        log.error(e.getMessage(), e);