1. 添加对Redis连接失败异常的捕获,尝试分析Redis连接失败原因

2. 在配置文件dev和test中添加Redis密码

(cherry picked from commit 9d8c1488c9)
This commit is contained in:
EnderByEndera
2024-05-11 16:47:42 +08:00
committed by PushM
parent 0b0f6de297
commit 6cb44f6a80
3 changed files with 11 additions and 1 deletions

View File

@@ -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连接失败");
}
}

View File

@@ -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);
}

View File

@@ -45,6 +45,7 @@ spring:
max-idle: 5
min-idle: 1
connect-timeout: 1000
password: aiihhbfcsy123!@#
mybatis: