From 6cb44f6a80ee76355161506b35ac66fbcedec9f1 Mon Sep 17 00:00:00 2001 From: EnderByEndera <707475564@qq.com> Date: Sat, 11 May 2024 16:47:42 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=B7=BB=E5=8A=A0=E5=AF=B9Redis=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E5=A4=B1=E8=B4=A5=E5=BC=82=E5=B8=B8=E7=9A=84=E6=8D=95?= =?UTF-8?q?=E8=8E=B7=EF=BC=8C=E5=B0=9D=E8=AF=95=E5=88=86=E6=9E=90Redis?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E5=A4=B1=E8=B4=A5=E5=8E=9F=E5=9B=A0=202.=20?= =?UTF-8?q?=E5=9C=A8=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6dev=E5=92=8Ctest?= =?UTF-8?q?=E4=B8=AD=E6=B7=BB=E5=8A=A0Redis=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 9d8c1488c9317d2c016a218d461c340884bb41ed) --- .../configuration/exception/GlobalExceptionHandler.java | 9 +++++++++ .../realtime/protection/server/task/TaskController.java | 2 +- src/main/resources/config/application-dev.yml | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/realtime/protection/configuration/exception/GlobalExceptionHandler.java b/src/main/java/com/realtime/protection/configuration/exception/GlobalExceptionHandler.java index 113b0e9..870f989 100644 --- a/src/main/java/com/realtime/protection/configuration/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/realtime/protection/configuration/exception/GlobalExceptionHandler.java @@ -5,11 +5,13 @@ import cn.dev33.satoken.exception.SaTokenException; import com.realtime.protection.configuration.response.ResponseResult; import com.realtime.protection.configuration.utils.enums.StateEnum; import com.realtime.protection.server.task.status.StateChangeService; +import io.lettuce.core.RedisConnectionException; import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.exceptions.PersistenceException; import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.core.annotation.Order; import org.springframework.dao.DuplicateKeyException; +import org.springframework.data.redis.RedisConnectionFailureException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @@ -112,4 +114,11 @@ public class GlobalExceptionHandler { log.error(responseResult.getMessage()); return responseResult; } + + @Order(2) + @ExceptionHandler(value = RedisConnectionFailureException.class) + public ResponseResult handleRedisConnectionException(RedisConnectionFailureException e) { + log.warn("Redis连接失败,具体原因:{}", e.getCause().getMessage()); + return ResponseResult.error().setMessage("Redis连接失败"); + } } diff --git a/src/main/java/com/realtime/protection/server/task/TaskController.java b/src/main/java/com/realtime/protection/server/task/TaskController.java index c520305..5542da2 100644 --- a/src/main/java/com/realtime/protection/server/task/TaskController.java +++ b/src/main/java/com/realtime/protection/server/task/TaskController.java @@ -182,7 +182,7 @@ public class TaskController implements TaskControllerApi { } } if (!errorIds.isEmpty()) { - return new ResponseResult(400, "id or status is invalid") + return ResponseResult.invalid() .setData("tasks_id", errorIds) .setData("success", false); } diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml index 4dd862a..32da1ea 100644 --- a/src/main/resources/config/application-dev.yml +++ b/src/main/resources/config/application-dev.yml @@ -45,6 +45,7 @@ spring: max-idle: 5 min-idle: 1 connect-timeout: 1000 + password: aiihhbfcsy123!@# mybatis: