fix(项目管理): 修改文件库交互,当测试连接不通或者添加不到文件时给出更好的报错信息

--bug=1017581 --user=宋天阳 [项目设置]
github#18347文件管理-git存储库,测试链接失败时间过长,且错误原因不清晰
https://www.tapd.cn/55049933/s/1258652
This commit is contained in:
song-tianyang 2022-10-11 17:56:42 +08:00 committed by 建国
parent 8156ffef1f
commit 12af180b4b
1 changed files with 8 additions and 3 deletions

View File

@ -135,7 +135,7 @@ public class GitRepositoryUtil {
} }
} catch (Exception e) { } catch (Exception e) {
LogUtil.error("获取文件库文件报错!", e); LogUtil.error("获取文件库文件报错!", e);
MSException.throwException("Connect repository error!"); MSException.throwException("Connect repository error! " + e.getLocalizedMessage());
} finally { } finally {
this.closeConnection(repo); this.closeConnection(repo);
} }
@ -179,6 +179,7 @@ public class GitRepositoryUtil {
List<String> returnList = new ArrayList<>(); List<String> returnList = new ArrayList<>();
this.validateParams(repositoryUrl, userName, token); this.validateParams(repositoryUrl, userName, token);
InMemoryRepository repo = null; InMemoryRepository repo = null;
String errorMsg = null;
try { try {
Collection<Ref> refList; Collection<Ref> refList;
UsernamePasswordCredentialsProvider pro = new UsernamePasswordCredentialsProvider(userName, token); UsernamePasswordCredentialsProvider pro = new UsernamePasswordCredentialsProvider(userName, token);
@ -187,13 +188,17 @@ public class GitRepositoryUtil {
returnList.add(item.getName()); returnList.add(item.getName());
}); });
} catch (Exception e) { } catch (Exception e) {
errorMsg = e.getMessage();
LogUtil.error("获取文件库文件报错!", e); LogUtil.error("获取文件库文件报错!", e);
} finally { } finally {
this.closeConnection(repo); this.closeConnection(repo);
} }
if (CollectionUtils.isEmpty(returnList)) { if (StringUtils.isNotBlank(errorMsg)) {
MSException.throwException("Repository connect error!"); MSException.throwException("Repository connect error! " + errorMsg);
} else if (CollectionUtils.isEmpty(returnList)) {
MSException.throwException("Repository connect error! Not find branches!");
} }
return returnList; return returnList;
} }