update 优化远程调用异常处理

2.X
疯狂的狮子li 3 years ago
parent 1fc833d876
commit a90cb2b6b3

@ -1,5 +1,6 @@
package com.ruoyi.system.api; package com.ruoyi.system.api;
import com.ruoyi.common.core.exception.user.UserException;
import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser; import com.ruoyi.system.api.model.LoginUser;
@ -16,7 +17,7 @@ public interface RemoteUserService {
* @param username * @param username
* @return * @return
*/ */
LoginUser getUserInfo(String username); LoginUser getUserInfo(String username) throws UserException;
/** /**
* *

@ -6,7 +6,6 @@ import com.ruoyi.auth.form.RegisterBody;
import com.ruoyi.common.core.constant.CacheConstants; import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.enums.UserType; import com.ruoyi.common.core.enums.UserType;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.exception.user.UserException; import com.ruoyi.common.core.exception.user.UserException;
import com.ruoyi.common.core.utils.MessageUtils; import com.ruoyi.common.core.utils.MessageUtils;
import com.ruoyi.common.core.utils.ServletUtils; import com.ruoyi.common.core.utils.ServletUtils;
@ -39,19 +38,7 @@ public class SysLoginService {
* *
*/ */
public LoginUser login(String username, String password) { public LoginUser login(String username, String password) {
LoginUser userInfo; LoginUser userInfo = remoteUserService.getUserInfo(username);
try {
// 查询用户信息
userInfo = remoteUserService.getUserInfo(username);
if (ObjectUtil.isNull(userInfo)) {
recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.not.exists", username));
throw new UserException("user.not.exists", username);
}
} catch (Exception e) {
recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage());
throw new ServiceException(e.getMessage());
}
// 获取用户登录错误次数(可自定义限制策略 例如: key + username + ip) // 获取用户登录错误次数(可自定义限制策略 例如: key + username + ip)
Integer errorNumber = RedisUtils.getCacheObject(CacheConstants.LOGIN_ERROR + username); Integer errorNumber = RedisUtils.getCacheObject(CacheConstants.LOGIN_ERROR + username);

@ -35,7 +35,7 @@ public class RemoteUserServiceImpl implements RemoteUserService {
private final ISysConfigService configService; private final ISysConfigService configService;
@Override @Override
public LoginUser getUserInfo(String username) { public LoginUser getUserInfo(String username) throws UserException {
SysUser sysUser = userService.selectUserByUserName(username); SysUser sysUser = userService.selectUserByUserName(username);
if (ObjectUtil.isNull(sysUser)) { if (ObjectUtil.isNull(sysUser)) {
throw new UserException("user.not.exists", username); throw new UserException("user.not.exists", username);

Loading…
Cancel
Save