diff --git a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizCmdbClient.java b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizCmdbClient.java index 3c9fceb388..e4aea5a1f4 100644 --- a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizCmdbClient.java +++ b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizCmdbClient.java @@ -28,6 +28,7 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import com.google.common.util.concurrent.UncheckedExecutionException; import com.tencent.bk.job.common.cc.config.CmdbConfig; import com.tencent.bk.job.common.cc.exception.CmdbException; import com.tencent.bk.job.common.cc.model.AppRoleDTO; @@ -82,6 +83,7 @@ import com.tencent.bk.job.common.esb.model.EsbReq; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.sdk.AbstractEsbSdkClient; +import com.tencent.bk.job.common.exception.InternalCmdbException; import com.tencent.bk.job.common.exception.InternalException; import com.tencent.bk.job.common.gse.service.QueryAgentStatusClient; import com.tencent.bk.job.common.metrics.CommonMetricNames; @@ -235,8 +237,13 @@ public InstanceTopologyDTO getBizInstCompleteTopology(long bizId) { public InstanceTopologyDTO getCachedBizInstCompleteTopology(long bizId) { try { return bizInstCompleteTopologyCache.get(bizId); - } catch (ExecutionException e) { - throw new InternalException(e, ErrorCode.CMDB_API_DATA_ERROR, null); + } catch (ExecutionException | UncheckedExecutionException e) { + Throwable cause = e.getCause(); + if (cause instanceof RuntimeException) { + throw (RuntimeException) cause; + } else { + throw new InternalException(e, ErrorCode.INTERNAL_ERROR, null); + } } } @@ -340,7 +347,7 @@ public EsbResp requestCmdbApi(String method, String errorMsg = "Fail to request CMDB data|method=" + method + "|uri=" + uri + "|reqStr=" + reqStr; log.error(errorMsg, e); status = "error"; - throw new InternalException(e.getMessage(), e, ErrorCode.CMDB_API_DATA_ERROR); + throw new InternalCmdbException(e.getMessage(), e, ErrorCode.CMDB_API_DATA_ERROR); } finally { HttpMetricUtil.clearHttpMetric(); long end = System.nanoTime(); @@ -730,7 +737,7 @@ public List getAllBizApps() { SearchAppResult data = esbResp.getData(); if (data == null) { appList.clear(); - throw new InternalException("Data is null", ErrorCode.CMDB_API_DATA_ERROR); + throw new InternalCmdbException("Data is null", ErrorCode.CMDB_API_DATA_ERROR); } List businessInfos = data.getInfo(); if (businessInfos != null && !businessInfos.isEmpty()) { @@ -770,11 +777,11 @@ public ApplicationDTO getBizAppById(long bizId) { }); SearchAppResult data = esbResp.getData(); if (data == null) { - throw new InternalException("data is null", ErrorCode.CMDB_API_DATA_ERROR); + throw new InternalCmdbException("data is null", ErrorCode.CMDB_API_DATA_ERROR); } List businessInfos = data.getInfo(); if (businessInfos == null || businessInfos.isEmpty()) { - throw new InternalException("data is null", ErrorCode.CMDB_API_DATA_ERROR); + throw new InternalCmdbException("data is null", ErrorCode.CMDB_API_DATA_ERROR); } return convertToAppInfo(businessInfos.get(0)); } diff --git a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizSetCmdbClient.java b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizSetCmdbClient.java index e1094d8c5e..5bd464d56a 100644 --- a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizSetCmdbClient.java +++ b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizSetCmdbClient.java @@ -45,7 +45,7 @@ import com.tencent.bk.job.common.esb.model.EsbReq; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.sdk.AbstractEsbSdkClient; -import com.tencent.bk.job.common.exception.InternalException; +import com.tencent.bk.job.common.exception.InternalCmdbException; import com.tencent.bk.job.common.util.http.HttpHelperFactory; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; @@ -102,11 +102,11 @@ public int searchBizSetCount() { new TypeReference>() { }); if (!resp.getResult()) { - throw new InternalException(ErrorCode.CMDB_API_DATA_ERROR, null); + throw new InternalCmdbException(ErrorCode.CMDB_API_DATA_ERROR, null); } return resp.getData().getCount(); } catch (Exception e) { - throw new InternalException(e, ErrorCode.CMDB_API_DATA_ERROR, null); + throw new InternalCmdbException(e, ErrorCode.CMDB_API_DATA_ERROR, null); } } @@ -153,11 +153,11 @@ private List searchBizSet(BizSetFilter filter, int start, int limit) new TypeReference>() { }); if (!resp.getResult() || resp.getData() == null) { - throw new InternalException(ErrorCode.CMDB_API_DATA_ERROR, null); + throw new InternalCmdbException(ErrorCode.CMDB_API_DATA_ERROR, null); } return resp.getData().getBizSetList(); } catch (Exception e) { - throw new InternalException(e, ErrorCode.CMDB_API_DATA_ERROR, null); + throw new InternalCmdbException(e, ErrorCode.CMDB_API_DATA_ERROR, null); } } @@ -183,11 +183,11 @@ private int searchBizCountInBusinessSet(long bizSetId) { new TypeReference>() { }); if (!resp.getResult()) { - throw new InternalException(ErrorCode.CMDB_API_DATA_ERROR, null); + throw new InternalCmdbException(ErrorCode.CMDB_API_DATA_ERROR, null); } return resp.getData().getCount(); } catch (Exception e) { - throw new InternalException(e, ErrorCode.CMDB_API_DATA_ERROR, null); + throw new InternalCmdbException(e, ErrorCode.CMDB_API_DATA_ERROR, null); } } @@ -226,11 +226,11 @@ private List searchBizInBizSet(long bizSetId, int start, int limit) { new TypeReference>() { }); if (!resp.getResult() || resp.getData() == null) { - throw new InternalException(ErrorCode.CMDB_API_DATA_ERROR, null); + throw new InternalCmdbException(ErrorCode.CMDB_API_DATA_ERROR, null); } return resp.getData().getBizList(); } catch (Exception e) { - throw new InternalException(e, ErrorCode.CMDB_API_DATA_ERROR, null); + throw new InternalCmdbException(e, ErrorCode.CMDB_API_DATA_ERROR, null); } } @@ -266,11 +266,11 @@ public ResourceWatchResult getBizSetEvents(Long startTime, St }, HttpHelperFactory.getLongRetryableHttpHelper()); if (!resp.getResult()) { - throw new InternalException(ErrorCode.CMDB_API_DATA_ERROR, null); + throw new InternalCmdbException(ErrorCode.CMDB_API_DATA_ERROR, null); } return resp.getData(); } catch (Exception e) { - throw new InternalException(e, ErrorCode.CMDB_API_DATA_ERROR, null); + throw new InternalCmdbException(e, ErrorCode.CMDB_API_DATA_ERROR, null); } } @@ -290,11 +290,11 @@ public ResourceWatchResult getBizSetRelationEvents(Lo }, HttpHelperFactory.getLongRetryableHttpHelper()); if (!resp.getResult()) { - throw new InternalException(ErrorCode.CMDB_API_DATA_ERROR, null); + throw new InternalCmdbException(ErrorCode.CMDB_API_DATA_ERROR, null); } return resp.getData(); } catch (Exception e) { - throw new InternalException(e, ErrorCode.CMDB_API_DATA_ERROR, null); + throw new InternalCmdbException(e, ErrorCode.CMDB_API_DATA_ERROR, null); } } diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties index 80e8bbac0a..dee57d6784 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties @@ -81,7 +81,7 @@ 1214002=制品库中找不到节点:{0},请到制品库核实 #IAM接口返回数据结构异常 -1215001=IAM接口返回数据结构异常 +1215001=IAM接口数据异常 #第三方API请求错误 1216001=第三方API请求错误 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties index 80e8bbac0a..dee57d6784 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties @@ -81,7 +81,7 @@ 1214002=制品库中找不到节点:{0},请到制品库核实 #IAM接口返回数据结构异常 -1215001=IAM接口返回数据结构异常 +1215001=IAM接口数据异常 #第三方API请求错误 1216001=第三方API请求错误 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties index 80e8bbac0a..dee57d6784 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties @@ -81,7 +81,7 @@ 1214002=制品库中找不到节点:{0},请到制品库核实 #IAM接口返回数据结构异常 -1215001=IAM接口返回数据结构异常 +1215001=IAM接口数据异常 #第三方API请求错误 1216001=第三方API请求错误 diff --git a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/client/EsbIamClient.java b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/client/EsbIamClient.java index b1caf0f366..0ce58f9d17 100644 --- a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/client/EsbIamClient.java +++ b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/client/EsbIamClient.java @@ -25,9 +25,11 @@ package com.tencent.bk.job.common.iam.client; import com.fasterxml.jackson.core.type.TypeReference; +import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.model.EsbReq; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.sdk.AbstractEsbSdkClient; +import com.tencent.bk.job.common.exception.InternalIamException; import com.tencent.bk.job.common.iam.dto.AuthByPathReq; import com.tencent.bk.job.common.iam.dto.BatchAuthByPathReq; import com.tencent.bk.job.common.iam.dto.EsbIamAction; @@ -179,6 +181,8 @@ private EsbResp requestIamApi(String method, HttpMetricUtil.setHttpMetricName(CommonMetricNames.ESB_IAM_API_HTTP); HttpMetricUtil.addTagForCurrentMetric(Tag.of("api_name", uri)); return getEsbRespByReq(method, uri, reqBody, typeReference); + } catch (Exception e) { + throw new InternalIamException(e, ErrorCode.IAM_API_DATA_ERROR, null); } finally { HttpMetricUtil.clearHttpMetric(); } diff --git a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/http/IamHttpClientServiceImpl.java b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/http/IamHttpClientServiceImpl.java index ced049e5eb..1158e47bde 100644 --- a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/http/IamHttpClientServiceImpl.java +++ b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/http/IamHttpClientServiceImpl.java @@ -24,6 +24,8 @@ package com.tencent.bk.job.common.iam.http; +import com.tencent.bk.job.common.constant.ErrorCode; +import com.tencent.bk.job.common.exception.InternalIamException; import com.tencent.bk.job.common.metrics.CommonMetricNames; import com.tencent.bk.job.common.util.http.ExtHttpHelper; import com.tencent.bk.job.common.util.http.HttpHelperFactory; @@ -58,6 +60,8 @@ public String doHttpGet(String uri) { HttpMetricUtil.setHttpMetricName(CommonMetricNames.IAM_API_HTTP); HttpMetricUtil.addTagForCurrentMetric(Tag.of("api_name", uri)); return httpHelper.get(buildUrl(uri), buildAuthHeader()); + } catch (Exception e) { + throw new InternalIamException(e, ErrorCode.IAM_API_DATA_ERROR, null); } finally { HttpMetricUtil.clearHttpMetric(); } @@ -71,7 +75,7 @@ public String doHttpPost(String uri, Object body) { return httpHelper.post(buildUrl(uri), DEFAULT_CHARSET, JsonUtils.toJson(body), buildAuthHeader()); } catch (Exception e) { log.error("Fail to request IAM", e); - return null; + throw new InternalIamException(e, ErrorCode.IAM_API_DATA_ERROR, null); } finally { HttpMetricUtil.clearHttpMetric(); } @@ -85,7 +89,7 @@ public String doHttpPut(String uri, Object body) { return httpHelper.put(buildUrl(uri), DEFAULT_CHARSET, JsonUtils.toJson(body), buildAuthHeader()); } catch (Exception e) { log.error("Fail to request IAM", e); - return null; + throw new InternalIamException(e, ErrorCode.IAM_API_DATA_ERROR, null); } finally { HttpMetricUtil.clearHttpMetric(); } @@ -97,6 +101,8 @@ public String doHttpDelete(String uri) { HttpMetricUtil.setHttpMetricName(CommonMetricNames.IAM_API_HTTP); HttpMetricUtil.addTagForCurrentMetric(Tag.of("api_name", uri)); return httpHelper.delete(buildUrl(uri), buildAuthHeader()); + } catch (Exception e) { + throw new InternalIamException(e, ErrorCode.IAM_API_DATA_ERROR, null); } finally { HttpMetricUtil.clearHttpMetric(); } diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/ErrorCode.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/ErrorCode.java index 47f7ff418c..1bbe66b1a0 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/ErrorCode.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/ErrorCode.java @@ -415,7 +415,7 @@ public class ErrorCode { // 制品库中找不到节点:{0},请到制品库核实 public static final int CAN_NOT_FIND_NODE_IN_ARTIFACTORY = 1214002; - // IAM接口返回数据结构异常- 一般是被网关防火墙重定向返回统一登录页面 + // IAM接口数据异常- 一般是被网关防火墙重定向返回统一登录页面 public static final int IAM_API_DATA_ERROR = 1215001; // 第三方API请求错误 diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/exception/InternalCmdbException.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/exception/InternalCmdbException.java new file mode 100644 index 0000000000..94a3a08fb4 --- /dev/null +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/exception/InternalCmdbException.java @@ -0,0 +1,29 @@ +package com.tencent.bk.job.common.exception; + +import lombok.Getter; +import lombok.ToString; + +/** + * 内部服务异常--调用CMDB异常 + */ +@Getter +@ToString +public class InternalCmdbException extends InternalException { + + public InternalCmdbException(Throwable cause, Integer errorCode, Object[] errorParams) { + super(cause, errorCode, errorParams); + } + + public InternalCmdbException(String message, Throwable cause, Integer errorCode) { + super(message, cause, errorCode); + } + + public InternalCmdbException(String message, Integer errorCode) { + super(message, errorCode); + } + + public InternalCmdbException(Integer errorCode, Object[] errorParams) { + super(errorCode, errorParams); + } + +} diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/exception/InternalCmsiException.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/exception/InternalCmsiException.java new file mode 100644 index 0000000000..408ab3fe27 --- /dev/null +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/exception/InternalCmsiException.java @@ -0,0 +1,16 @@ +package com.tencent.bk.job.common.exception; + +import lombok.Getter; +import lombok.ToString; + +/** + * 内部服务异常--调用cmsi接口异常 + */ +@Getter +@ToString +public class InternalCmsiException extends InternalException { + + public InternalCmsiException(String message, Throwable cause, Integer errorCode) { + super(message, cause, errorCode); + } +} diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/exception/InternalIamException.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/exception/InternalIamException.java new file mode 100644 index 0000000000..5bf8fb5058 --- /dev/null +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/exception/InternalIamException.java @@ -0,0 +1,24 @@ +package com.tencent.bk.job.common.exception; + +import lombok.Getter; +import lombok.ToString; + +/** + * 内部服务异常--调用IAM异常 + */ +@Getter +@ToString +public class InternalIamException extends InternalException { + + public InternalIamException(Throwable cause, Integer errorCode, Object[] errorParams) { + super(cause, errorCode, errorParams); + } + + public InternalIamException(String message, Integer errorCode) { + super(message, errorCode); + } + + public InternalIamException(String message, Throwable cause, Integer errorCode) { + super(message, cause, errorCode); + } +} diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/exception/InternalUserManageException.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/exception/InternalUserManageException.java new file mode 100644 index 0000000000..99e42c9308 --- /dev/null +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/exception/InternalUserManageException.java @@ -0,0 +1,16 @@ +package com.tencent.bk.job.common.exception; + +import lombok.Getter; +import lombok.ToString; + +/** + * 内部服务异常--用户管理异常 + */ +@Getter +@ToString +public class InternalUserManageException extends InternalException { + + public InternalUserManageException(String message, Throwable cause, Integer errorCode) { + super(message, cause, errorCode); + } +} diff --git a/src/backend/commons/paas-sdk/src/main/java/com/tencent/bk/job/common/paas/login/EELoginClient.java b/src/backend/commons/paas-sdk/src/main/java/com/tencent/bk/job/common/paas/login/EELoginClient.java index 8488f08faf..4c55d2f528 100644 --- a/src/backend/commons/paas-sdk/src/main/java/com/tencent/bk/job/common/paas/login/EELoginClient.java +++ b/src/backend/commons/paas-sdk/src/main/java/com/tencent/bk/job/common/paas/login/EELoginClient.java @@ -25,9 +25,11 @@ package com.tencent.bk.job.common.paas.login; import com.fasterxml.jackson.core.type.TypeReference; +import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.model.EsbReq; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.sdk.AbstractEsbSdkClient; +import com.tencent.bk.job.common.exception.InternalUserManageException; import com.tencent.bk.job.common.metrics.CommonMetricNames; import com.tencent.bk.job.common.model.dto.BkUserDTO; import com.tencent.bk.job.common.paas.model.EsbUserDto; @@ -80,6 +82,10 @@ private BkUserDTO getUserInfo(EsbReq esbReq) { } ); return convertToBkUserDTO(esbResp.getData()); + } catch (Exception e) { + String errorMsg = "Get " + API_GET_USER_INFO + " error"; + log.error(errorMsg, e); + throw new InternalUserManageException(errorMsg, e, ErrorCode.USER_MANAGE_API_ACCESS_ERROR); } finally { HttpMetricUtil.clearHttpMetric(); } diff --git a/src/backend/commons/paas-sdk/src/main/java/com/tencent/bk/job/common/paas/user/EEPaasClient.java b/src/backend/commons/paas-sdk/src/main/java/com/tencent/bk/job/common/paas/user/EEPaasClient.java index b848c0f122..c6a0e6f146 100644 --- a/src/backend/commons/paas-sdk/src/main/java/com/tencent/bk/job/common/paas/user/EEPaasClient.java +++ b/src/backend/commons/paas-sdk/src/main/java/com/tencent/bk/job/common/paas/user/EEPaasClient.java @@ -30,7 +30,8 @@ import com.tencent.bk.job.common.esb.metrics.EsbMetricTags; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.sdk.AbstractEsbSdkClient; -import com.tencent.bk.job.common.exception.InternalException; +import com.tencent.bk.job.common.exception.InternalCmsiException; +import com.tencent.bk.job.common.exception.InternalUserManageException; import com.tencent.bk.job.common.metrics.CommonMetricNames; import com.tencent.bk.job.common.model.dto.BkUserDTO; import com.tencent.bk.job.common.model.error.ErrorType; @@ -115,7 +116,7 @@ public List getUserList(String fields, } catch (Exception e) { String errorMsg = "Get " + API_GET_USER_LIST + " error"; log.error(errorMsg, e); - throw new InternalException(errorMsg, e, ErrorCode.USER_MANAGE_API_ACCESS_ERROR); + throw new InternalUserManageException(errorMsg, e, ErrorCode.USER_MANAGE_API_ACCESS_ERROR); } finally { HttpMetricUtil.clearHttpMetric(); } @@ -166,6 +167,10 @@ public List getNotifyChannelList(String uin) { } ); return esbResp.getData(); + } catch (Exception e) { + String errorMsg = "Get " + API_GET_NOTIFY_CHANNEL_LIST + " error"; + log.error(errorMsg, e); + throw new InternalCmsiException(errorMsg, e, ErrorCode.CMSI_MSG_CHANNEL_DATA_ERROR); } finally { HttpMetricUtil.clearHttpMetric(); } diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/web/service/impl/LoginServiceImpl.java b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/web/service/impl/LoginServiceImpl.java index 116db99e7a..9b8bd8ac35 100644 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/web/service/impl/LoginServiceImpl.java +++ b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/web/service/impl/LoginServiceImpl.java @@ -27,6 +27,7 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import com.google.common.util.concurrent.UncheckedExecutionException; import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.InternalException; import com.tencent.bk.job.common.model.dto.BkUserDTO; @@ -104,9 +105,14 @@ public BkUserDTO getUser(String bkToken) { try { Optional userDto = onlineUserCache.get(bkToken); return userDto.orElse(null); - } catch (ExecutionException e) { + } catch (ExecutionException | UncheckedExecutionException e) { log.warn("Error occur when get user from paas!"); - throw new InternalException("Query userinfo from paas fail", e, ErrorCode.USER_MANAGE_API_ACCESS_ERROR); + Throwable cause = e.getCause(); + if (cause instanceof RuntimeException) { + throw (RuntimeException) cause; + } else { + throw new InternalException("Query userinfo from paas fail", e, ErrorCode.INTERNAL_ERROR); + } } } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/notify/impl/NotifyEsbChannelDAOImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/notify/impl/NotifyEsbChannelDAOImpl.java index bb41e22346..8dadbf3655 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/notify/impl/NotifyEsbChannelDAOImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/notify/impl/NotifyEsbChannelDAOImpl.java @@ -27,6 +27,7 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import com.google.common.util.concurrent.UncheckedExecutionException; import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.InternalException; import com.tencent.bk.job.common.util.JobContextUtil; @@ -93,10 +94,15 @@ public List listNotifyEsbChannel(DSLContext dslContext) { try { String lang = JobContextUtil.getUserLang(); return esbChannelCache.get(lang); - } catch (ExecutionException e) { + } catch (ExecutionException | UncheckedExecutionException e) { String errorMsg = "Fail to load EsbChannel from cache"; logger.error(errorMsg, e); - throw new InternalException(errorMsg, e, ErrorCode.CMSI_MSG_CHANNEL_DATA_ERROR); + Throwable cause = e.getCause(); + if (cause instanceof RuntimeException) { + throw (RuntimeException) cause; + } else { + throw new InternalException(errorMsg, e, ErrorCode.INTERNAL_ERROR); + } } } } diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/IamClient.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/IamClient.java index b30a2f7cfa..9208d9e2a7 100644 --- a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/IamClient.java +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/IamClient.java @@ -26,7 +26,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.exception.InternalException; +import com.tencent.bk.job.common.exception.InternalIamException; import com.tencent.bk.job.common.util.StringUtil; import com.tencent.bk.job.common.util.http.ExtHttpHelper; import com.tencent.bk.job.common.util.json.JsonMapper; @@ -83,7 +83,7 @@ private R getIamRespByReq(String method, String uri, IamReq reqBody, Type } if (StringUtils.isBlank(respStr)) { log.error("fail:response is blank|method={}|uri={}|reqStr={}", method, uri, reqStr); - throw new InternalException("response is blank", ErrorCode.IAM_API_DATA_ERROR); + throw new InternalIamException("response is blank", ErrorCode.IAM_API_DATA_ERROR); } else { log.debug("success|method={}|uri={}|reqStr={}|respStr={}", method, uri, reqStr, respStr); } @@ -92,7 +92,7 @@ private R getIamRespByReq(String method, String uri, IamReq reqBody, Type if (iamResp == null) { log.error("fail:iamResp is null after parse|method={}|uri={}|reqStr={}|respStr={}", method, uri, reqStr, respStr); - throw new InternalException("iamResp is null after parse", ErrorCode.IAM_API_DATA_ERROR); + throw new InternalIamException("iamResp is null after parse", ErrorCode.IAM_API_DATA_ERROR); } else if (iamResp.getCode() != RESULT_OK) { log.error( "fail:iamResp code!=0|iamResp.code={}|iamResp" + @@ -101,7 +101,7 @@ private R getIamRespByReq(String method, String uri, IamReq reqBody, Type , iamResp.getMessage() , method, uri, reqStr, respStr ); - throw new InternalException("iamResp code!=0", ErrorCode.IAM_API_DATA_ERROR); + throw new InternalIamException("iamResp code!=0", ErrorCode.IAM_API_DATA_ERROR); } if (iamResp.getData() == null) { log.warn( @@ -116,7 +116,7 @@ private R getIamRespByReq(String method, String uri, IamReq reqBody, Type } catch (Throwable e) { String errorMsg = "Fail to request IAM data|method=" + method + "|uri=" + uri + "|reqStr=" + reqStr; log.error(errorMsg, e); - throw new InternalException("Fail to request IAM data", e, ErrorCode.IAM_API_DATA_ERROR); + throw new InternalIamException("Fail to request IAM data", e, ErrorCode.IAM_API_DATA_ERROR); } }