From 0c01b42b8c3073574d63762bb4bb26bc2fe370d0 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sun, 4 Jun 2023 03:15:00 +0800 Subject: [PATCH] Fixed can not search [] bug --- .../handler/CustomExceptionHandler.java | 4 ++++ ui/src/constants/Common.constants.ts | 2 ++ ui/src/services/index.ts | 20 +++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/Pinnacle/src/main/java/com/cfive/pinnacle/handler/CustomExceptionHandler.java b/Pinnacle/src/main/java/com/cfive/pinnacle/handler/CustomExceptionHandler.java index fc50043..65f5b1a 100644 --- a/Pinnacle/src/main/java/com/cfive/pinnacle/handler/CustomExceptionHandler.java +++ b/Pinnacle/src/main/java/com/cfive/pinnacle/handler/CustomExceptionHandler.java @@ -9,6 +9,7 @@ import com.cfive.pinnacle.exception.TokenHasExpiredException; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DuplicateKeyException; +import org.springframework.jdbc.UncategorizedSQLException; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.DisabledException; @@ -49,6 +50,9 @@ public class CustomExceptionHandler { if (e instanceof DataValidationFailedException) { return ResponseResult.build(ResponseCode.DATABASE_DATA_VALIDATION_FAILED, e.getMessage(), null); } + if (e instanceof UncategorizedSQLException) { + return ResponseResult.build(ResponseCode.DATABASE_EXECUTE_ERROR, "error", null); + } log.debug(e.getMessage(), e); diff --git a/ui/src/constants/Common.constants.ts b/ui/src/constants/Common.constants.ts index 2ecd1af..4ee31e6 100644 --- a/ui/src/constants/Common.constants.ts +++ b/ui/src/constants/Common.constants.ts @@ -32,6 +32,7 @@ const DATABASE_TIMEOUT_ERROR = 20035 const DATABASE_CONNECT_ERROR = 20036 const DATABASE_DATA_TO_LONG = 20037 const DATABASE_DATA_VALIDATION_FAILED = 20038 +const DATABASE_EXECUTE_ERROR = 20039 const UNAUTHORIZED = 30010 const ACCESS_DENIED = 30030 @@ -73,6 +74,7 @@ export { DATABASE_CONNECT_ERROR, DATABASE_DATA_TO_LONG, DATABASE_DATA_VALIDATION_FAILED, + DATABASE_EXECUTE_ERROR, UNAUTHORIZED, ACCESS_DENIED, USER_DISABLE, diff --git a/ui/src/services/index.ts b/ui/src/services/index.ts index 387d657..5648eeb 100644 --- a/ui/src/services/index.ts +++ b/ui/src/services/index.ts @@ -6,6 +6,7 @@ import { ACCESS_DENIED, DATABASE_DATA_TO_LONG, DATABASE_DATA_VALIDATION_FAILED, + DATABASE_EXECUTE_ERROR, TOKEN_HAS_EXPIRED, TOKEN_IS_ILLEGAL, TOKEN_RENEW_SUCCESS, @@ -19,6 +20,19 @@ const service = axios.create({ withCredentials: false }) +service.defaults.paramsSerializer = (params) => { + return Object.keys(params) + .filter((it) => { + // eslint-disable-next-line no-prototype-builtins + return params.hasOwnProperty(it) + }) + .reduce((pre, curr) => { + return params[curr] !== null + ? (pre !== '' ? pre + '&' : '') + curr + '=' + encodeURIComponent(params[curr]) + : pre + }, '') +} + service.interceptors.request.use( async (config) => { let token = getToken() @@ -83,6 +97,12 @@ service.interceptors.response.use( message: '数据验证失败' }) return await Promise.reject(response?.data) + case DATABASE_EXECUTE_ERROR: + ElMessage.error({ + dangerouslyUseHTMLString: true, + message: '数据库执行出错' + }) + return await Promise.reject(response?.data) } return response },