diff --git a/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/handler/RedisExceptionHandler.java b/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/handler/RedisExceptionHandler.java new file mode 100644 index 00000000..5ed12a6e --- /dev/null +++ b/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/handler/RedisExceptionHandler.java @@ -0,0 +1,30 @@ +package org.dromara.common.redis.handler; + +import cn.hutool.http.HttpStatus; +import com.baomidou.lock.exception.LockFailureException; +import jakarta.servlet.http.HttpServletRequest; +import lombok.extern.slf4j.Slf4j; +import org.dromara.common.core.domain.R; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +/** + * Redis异常处理器 + * + * @author AprilWind + */ +@Slf4j +@RestControllerAdvice +public class RedisExceptionHandler { + + /** + * 分布式锁Lock4j异常 + */ + @ExceptionHandler(LockFailureException.class) + public R handleLockFailureException(LockFailureException e, HttpServletRequest request) { + String requestURI = request.getRequestURI(); + log.error("获取锁失败了'{}',发生Lock4j异常." + requestURI, e.getMessage()); + return R.fail(HttpStatus.HTTP_UNAVAILABLE, "业务处理中,请稍后再试..."); + } + +}