2
0

feat: common support i18n

This commit is contained in:
zhangsz
2025-01-23 18:32:54 +08:00
parent c3f3ab872a
commit 9dd70b28ab
9 changed files with 81 additions and 33 deletions

View File

@@ -27,7 +27,7 @@ public class InnerAuthAspect implements Ordered
// 内部请求验证
if (!StringUtils.equals(SecurityConstants.INNER, source))
{
throw new InnerAuthException("没有内部访问权限,不允许访问");
throw new InnerAuthException("common.no.internal.access.permission");
}
String userid = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USER_ID);
@@ -35,7 +35,7 @@ public class InnerAuthAspect implements Ordered
// 用户信息验证
if (innerAuth.isUser() && (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)))
{
throw new InnerAuthException("没有设置用户信息,不允许访问 ");
throw new InnerAuthException("common.no.user.info");
}
return point.proceed();
}

View File

@@ -72,12 +72,12 @@ public class AuthLogic
String token = SecurityUtils.getToken();
if (token == null)
{
throw new NotLoginException("未提供token");
throw new NotLoginException("common.no.token");
}
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser == null)
{
throw new NotLoginException("无效的token");
throw new NotLoginException("common.invalid.token");
}
return loginUser;
}

View File

@@ -17,6 +17,7 @@ import org.wfc.common.core.exception.ServiceException;
import org.wfc.common.core.exception.auth.NotPermissionException;
import org.wfc.common.core.exception.auth.NotRoleException;
import org.wfc.common.core.text.Convert;
import org.wfc.common.core.utils.MessageUtils;
import org.wfc.common.core.utils.StringUtils;
import org.wfc.common.core.utils.html.EscapeUtil;
import org.wfc.common.core.web.domain.AjaxResult;
@@ -38,8 +39,8 @@ public class GlobalExceptionHandler
public AjaxResult handleNotPermissionException(NotPermissionException e, HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求地址'{}',权限码校验失败'{}'", requestURI, e.getMessage());
return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
log.error("Request address'{}',Permission code verification failed'{}'", requestURI, e.getMessage());
return AjaxResult.error(HttpStatus.FORBIDDEN, "common.no.permission");
}
/**
@@ -49,8 +50,8 @@ public class GlobalExceptionHandler
public AjaxResult handleNotRoleException(NotRoleException e, HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求地址'{}',角色权限校验失败'{}'", requestURI, e.getMessage());
return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
log.error("Request address'{}',Role permission verification failed'{}'", requestURI, e.getMessage());
return AjaxResult.error(HttpStatus.FORBIDDEN, "common.no.permission");
}
/**
@@ -60,7 +61,7 @@ public class GlobalExceptionHandler
public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod());
log.error("Request address'{}','{}' request not supported", requestURI, e.getMethod());
return AjaxResult.error(e.getMessage());
}
@@ -82,8 +83,8 @@ public class GlobalExceptionHandler
public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e);
return AjaxResult.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName()));
log.error("The required path variable '{}' is missing from the request path, and a system exception occurred.", requestURI, e);
return AjaxResult.error(MessageUtils.message("common.request.path.variable.not.blank", e.getVariableName()));
}
/**
@@ -98,8 +99,8 @@ public class GlobalExceptionHandler
{
value = EscapeUtil.clean(value);
}
log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e);
return AjaxResult.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), value));
log.error("The request parameter type does not match '{}', and a system exception occurred.", requestURI, e);
return AjaxResult.error(MessageUtils.message("common.request.parameter.type.not.match", e.getName(), e.getRequiredType().getName(), value));
}
/**
@@ -109,7 +110,7 @@ public class GlobalExceptionHandler
public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求地址'{}',发生未知异常.", requestURI, e);
log.error("Requesting address '{}', an unknown exception occurred.", requestURI, e);
return AjaxResult.error(e.getMessage());
}
@@ -120,7 +121,7 @@ public class GlobalExceptionHandler
public AjaxResult handleException(Exception e, HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求地址'{}',发生系统异常.", requestURI, e);
log.error("Requesting address '{}', an unknown exception occurred.", requestURI, e);
return AjaxResult.error(e.getMessage());
}
@@ -161,6 +162,6 @@ public class GlobalExceptionHandler
@ExceptionHandler(DemoModeException.class)
public AjaxResult handleDemoModeException(DemoModeException e)
{
return AjaxResult.error("演示模式,不允许操作");
return AjaxResult.error("common.demo.mode");
}
}

View File

@@ -126,7 +126,7 @@ public class TokenService
}
catch (Exception e)
{
log.error("获取用户信息异常'{}'", e.getMessage());
log.error("Exception in obtaining user information'{}'", e.getMessage());
}
return user;
}