2024年6月26日 更改异常处理,隐藏SQL错误,隐藏未注册用户提示

This commit is contained in:
bai 2024-06-26 22:44:52 +08:00
parent f654fb1615
commit 1cf148a66c
2 changed files with 22 additions and 3 deletions

View File

@ -5,10 +5,11 @@ import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException; import org.apache.shiro.authz.UnauthorizedException;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.enums.SentinelErrorInfoEnum; import org.jeecg.common.enums.SentinelErrorInfoEnum;
import org.springframework.dao.DataIntegrityViolationException; import org.springframework.core.NestedRuntimeException;
import org.springframework.dao.DuplicateKeyException; import org.springframework.dao.*;
import org.springframework.data.redis.connection.PoolException; import org.springframework.data.redis.connection.PoolException;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
@ -18,6 +19,10 @@ import org.springframework.web.servlet.NoHandlerFoundException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.sql.SQLException;
import java.sql.SQLNonTransientException;
import java.sql.SQLSyntaxErrorException;
/** /**
* 异常处理器 * 异常处理器
* *
@ -133,4 +138,17 @@ public class JeecgBootExceptionHandler {
return Result.error("Redis 连接异常!"); return Result.error("Redis 连接异常!");
} }
@ExceptionHandler({ SQLSyntaxErrorException.class, SQLNonTransientException.class, SQLException.class })
public Result<?> handleSQLSyntaxErrorException(SQLException e) {
log.error(e.getMessage(), e);
return Result.error("SQL语法错误");
}
@ExceptionHandler({ BadSqlGrammarException.class, InvalidDataAccessResourceUsageException.class, NonTransientDataAccessException.class, DataAccessException.class })
public Result<?> handleBadSqlGrammarException(DataAccessException e) {
log.error(e.getMessage(), e);
return Result.error("SQL语法错误");
}
} }

View File

@ -528,7 +528,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
Result<?> result = new Result<Object>(); Result<?> result = new Result<Object>();
//情况1根据用户信息查询该用户不存在 //情况1根据用户信息查询该用户不存在
if (sysUser == null) { if (sysUser == null) {
result.error500("该用户不存在,请注册"); //result.error500("该用户不存在,请注册");//不允许明确的提示
result.error500("用户名或密码错误");
baseCommonService.addLog("用户登录失败,用户不存在!", CommonConstant.LOG_TYPE_1, null); baseCommonService.addLog("用户登录失败,用户不存在!", CommonConstant.LOG_TYPE_1, null);
return result; return result;
} }