diff --git a/cf-gateway/src/main/java/com/cf/imes/gateway/filter/security/TokenAuthenticationFilter.java b/cf-gateway/src/main/java/com/cf/imes/gateway/filter/security/TokenAuthenticationFilter.java index 0b2d9eda7..947e4b107 100644 --- a/cf-gateway/src/main/java/com/cf/imes/gateway/filter/security/TokenAuthenticationFilter.java +++ b/cf-gateway/src/main/java/com/cf/imes/gateway/filter/security/TokenAuthenticationFilter.java @@ -152,6 +152,7 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered { if(commonResult != null) { Integer code = commonResult.getCode(); String msg = commonResult.getMsg(); + Object[] args = commonResult.getArgs(); if(code != 0) { if (TOKEN_TIME_IS_EXPIRES.getCode().equals(code)) { throw new ServiceException(TOKEN_TIME_IS_EXPIRES); @@ -160,9 +161,9 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered { } else if (ORGAN_NOT_EXISTS.getCode().equals(code)) { throw new ServiceException(ORGAN_NOT_EXISTS); } else if (ORGAN_DISABLE.getCode().equals(code)) { - throw new ServiceException(new ErrorCode(code, msg)); + throw new ServiceException(new ErrorCode(code, msg), args); } else if (ORGAN_EXPIRE.getCode().equals(code)) { - throw new ServiceException(new ErrorCode(code, msg)); + throw new ServiceException(new ErrorCode(code, msg), args); } } } diff --git a/cf-gateway/src/main/java/com/cf/imes/gateway/handler/GlobalExceptionHandler.java b/cf-gateway/src/main/java/com/cf/imes/gateway/handler/GlobalExceptionHandler.java index 186cb94b4..90d44e6ad 100644 --- a/cf-gateway/src/main/java/com/cf/imes/gateway/handler/GlobalExceptionHandler.java +++ b/cf-gateway/src/main/java/com/cf/imes/gateway/handler/GlobalExceptionHandler.java @@ -1,10 +1,13 @@ package com.cf.imes.gateway.handler; +import com.cf.imes.framework.common.constants.ResourceBundleConstants; import com.cf.imes.framework.common.exception.ServiceException; import com.cf.imes.framework.common.pojo.CommonResult; +import com.cf.imes.framework.common.util.i18n.core.util.ResourceBundleUtils; import com.cf.imes.gateway.util.WebFrameworkUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.core.annotation.Order; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; @@ -72,18 +75,19 @@ public class GlobalExceptionHandler implements ErrorWebExceptionHandler { log.error("[defaultExceptionHandler][uri({}/{}) 发生异常]", request.getURI(), request.getMethod(), ex); // TODO 晨丰:是否要插入异常日志呢? // 返回 ERROR CommonResult - return CommonResult.error(INTERNAL_SERVER_ERROR.getCode(), INTERNAL_SERVER_ERROR.getMsg()); + return CommonResult.error(INTERNAL_SERVER_ERROR.getCode(), ResourceBundleUtils.getMessage(ResourceBundleConstants.MESSAGE_ERROR_PATH, INTERNAL_SERVER_ERROR.getMsg(), null, LocaleContextHolder.getLocale(), null)); } @ExceptionHandler(value = ServiceException.class) public CommonResult serviceExceptionHandler(ServiceException ex) { + String errMsg = ResourceBundleUtils.getMessage(ResourceBundleConstants.MESSAGE_ERROR_PATH, ex.getMessage(), null, LocaleContextHolder.getLocale(), null); // 系统异常输出堆栈 - if(INTERNAL_SERVER_ERROR.getCode().equals(ex.getCode())) { + if (INTERNAL_SERVER_ERROR.getCode().equals(ex.getCode())) { log.info("[serviceExceptionHandler]", ex); } else { - log.info(String.format("==========[serviceExceptionHandler]==========,%s:%s", ex.getCode(), ex.getMessage())); + log.info(String.format("==========[serviceExceptionHandler]==========,%s:%s", ex.getCode(), errMsg)); } - return CommonResult.error(ex.getCode(), ex.getMessage()); + return CommonResult.error(ex.getCode(), errMsg); } } diff --git a/cf-gateway/src/main/resources/application.yaml b/cf-gateway/src/main/resources/application.yaml index 09f1c1b17..78b9fd0ba 100644 --- a/cf-gateway/src/main/resources/application.yaml +++ b/cf-gateway/src/main/resources/application.yaml @@ -16,6 +16,9 @@ spring: - optional:classpath:application-${spring.profiles.active}.yaml # 加载【本地】配置 - optional:nacos:${spring.application.name}-${spring.profiles.active}.yaml # 加载【Nacos】的配置 + messages: + basename: message_errorcode + cloud: # Spring Cloud Gateway 配置项,对应 GatewayProperties 类 gateway: diff --git a/cf-gateway/src/main/resources/message_errorcode.properties b/cf-gateway/src/main/resources/message_errorcode.properties new file mode 100644 index 000000000..8b082d8b0 --- /dev/null +++ b/cf-gateway/src/main/resources/message_errorcode.properties @@ -0,0 +1,6 @@ +token.time.is_expires=当前token已过期,请重新配置或延长时间 +token.config.not_exists=当前应用的token配置不存在 +organ.not_exists=组织不存在 +organ.disable=[{0}]组织已被禁用 +organ.expire=[{0}]组织已过期 +global.error.default.error=系统繁忙,请稍后再试 \ No newline at end of file diff --git a/cf-gateway/src/main/resources/message_errorcode_cht.properties b/cf-gateway/src/main/resources/message_errorcode_cht.properties new file mode 100644 index 000000000..79e33400e --- /dev/null +++ b/cf-gateway/src/main/resources/message_errorcode_cht.properties @@ -0,0 +1,6 @@ +token.time.is_expires=當前token已過期,請重新配置或延長時間 +token.config.not_exists=當前應用的token配置不存在 +organ.not_exists=組織不存在 +organ.disable=[{0}]組織已被禁用 +organ.expire=[{0}]組織已過期 +global.error.default.error=系統繁忙,請稍後再試 \ No newline at end of file diff --git a/cf-gateway/src/main/resources/message_errorcode_en.properties b/cf-gateway/src/main/resources/message_errorcode_en.properties new file mode 100644 index 000000000..c785078e3 --- /dev/null +++ b/cf-gateway/src/main/resources/message_errorcode_en.properties @@ -0,0 +1,6 @@ +token.time.is_expires=The current token has expired. Please reconfigure or extend the validity period +token.config.not_exists=The token configuration for the current application does not exist +organ.not_exists=Organization does not exist +organ.disable=Organization [{0}] has been disabled +organ.expire=Organization [{0}] has expired +global.error.default.error=System is busy, please try again later \ No newline at end of file