Browse Source

refactor: centralize code review errors

weipengtao 3 months ago
parent
commit
c2f80218ba

+ 17 - 49
web/src/main/java/cn/seecoder/web/controller/codereview/CodeReviewController.java

@@ -8,14 +8,10 @@ import cn.seecoder.web.model.vo.codereview.CodeReviewVO;
 import cn.seecoder.web.model.vo.codereview.FileReviewCreateVO;
 import cn.seecoder.web.service.codereview.BranchReviewService;
 import cn.seecoder.web.service.codereview.FileReviewService;
-import com.nju.edu.gitlab.SeecoderGitlabApi;
-import com.nju.edu.gitlab.SeecoderGitlabException;
 import io.swagger.annotations.*;
-import org.gitlab4j.api.GitLabApiException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
-import java.io.IOException;
 import java.util.List;
 
 /**
@@ -46,13 +42,9 @@ public class CodeReviewController {
     @PostMapping("/branch_review")
     @ApiOperation(value = "创建一个code_review", httpMethod = "POST")
     @ApiImplicitParam(value = "codeReviewCreateVO", dataType = "object", paramType = "body")
-    public Response createBranchReview(@RequestBody CodeReviewCreateVO codeReviewCreateVO){
-        try{
-            branchReviewService.create(codeReviewCreateVO);
-            return Response.buildSuccess();
-        } catch (RuntimeException exception) {
-            return Response.buildFailure(500, exception.getMessage());
-        }
+    public Response createBranchReview(@RequestBody CodeReviewCreateVO codeReviewCreateVO) throws ServiceException {
+        branchReviewService.create(codeReviewCreateVO);
+        return Response.buildSuccess();
     }
 
     @GetMapping("/branch_review/{codeReviewId}")
@@ -81,24 +73,16 @@ public class CodeReviewController {
     @PutMapping("/merge/{codeReviewId}")
     @ApiOperation(value = "合并某个code_review", httpMethod = "PUT")
     @ApiImplicitParam(value = "codeReviewId", dataType = "int", paramType = "query")
-    public Response merge(@PathVariable("codeReviewId") Integer codeReviewId) {
-        try{
-            branchReviewService.merge(codeReviewId);
-            return Response.buildSuccess();
-        } catch (SeecoderGitlabException | GitLabApiException exception) {
-            return Response.buildFailure(500, exception.getMessage());
-        }
+    public Response merge(@PathVariable("codeReviewId") Integer codeReviewId) throws ServiceException {
+        branchReviewService.merge(codeReviewId);
+        return Response.buildSuccess();
     }
 
     @ApiOperation(value = "获取指定项目的所有branch信息", httpMethod = "GET")
     @GetMapping("/branches/{projectId}")
     @ApiImplicitParam(name = "projectId", dataType = "int", paramType = "query")
-    public Response getProjectBranches(@PathVariable("projectId") Integer projectId){
-        try{
-            return Response.buildSuccess(branchReviewService.getBranches(projectId));
-        } catch (SeecoderGitlabException exception) {
-            return Response.buildFailure(500, exception.getMessage());
-        }
+    public Response getProjectBranches(@PathVariable("projectId") Integer projectId) throws ServiceException {
+        return Response.buildSuccess(branchReviewService.getBranches(projectId));
     }
 
     @ApiOperation(value = "获取两个分支的比较信息", httpMethod = "GET")
@@ -109,12 +93,8 @@ public class CodeReviewController {
             @ApiImplicitParam(name = "toBash", dataType = "String", paramType = "query")
     })
     public Response compare(@RequestParam("projectId")Integer projectId, @RequestParam("fromBash")String fromBash,
-                            @RequestParam("toBash") String toBash){
-        try{
-            return Response.buildSuccess(branchReviewService.compareBranches(projectId, fromBash, toBash));
-        } catch (SeecoderGitlabException exception) {
-            return Response.buildFailure(500, exception.getMessage());
-        }
+                            @RequestParam("toBash") String toBash) throws ServiceException {
+        return Response.buildSuccess(branchReviewService.compareBranches(projectId, fromBash, toBash));
     }
 
     @PostMapping("/file_review")
@@ -146,34 +126,22 @@ public class CodeReviewController {
     @GetMapping("/repository_tree")
     @ApiOperation(value = "获取仓库文件列表", httpMethod = "GET")
     public Response getRepositoryTree(@RequestParam("projectId") int projectId, @RequestParam("branch") String branch,
-                                      @RequestParam(value = "path", required = false) String path) {
-        try {
-            if(path != null) return Response.buildSuccess(fileReviewService.getRepositoryTree(projectId, branch, path));
-            else return Response.buildSuccess(fileReviewService.getRepositoryTree(projectId, branch));
-        } catch (SeecoderGitlabException exception) {
-            return Response.buildFailure(500, exception.getMessage());
-        }
+                                      @RequestParam(value = "path", required = false) String path) throws ServiceException {
+        if(path != null) return Response.buildSuccess(fileReviewService.getRepositoryTree(projectId, branch, path));
+        return Response.buildSuccess(fileReviewService.getRepositoryTree(projectId, branch));
     }
 
     @GetMapping("/invite")
     @ApiOperation(value = "通过手机号码邀请评审人", httpMethod = "GET")
-    public Response inviteReviewer(@RequestParam("phoneNumber") String phoneNumber) {
-        try {
-            return Response.buildSuccess(fileReviewService.inviteUser(phoneNumber));
-        } catch (ServiceException exception) {
-            return Response.buildFailure(exception.getCode(), exception.getMessage());
-        }
+    public Response inviteReviewer(@RequestParam("phoneNumber") String phoneNumber) throws ServiceException {
+        return Response.buildSuccess(fileReviewService.inviteUser(phoneNumber));
     }
 
     @GetMapping("/file_content")
     @ApiOperation(value = "获取某个文件的内容", httpMethod = "GET")
     public Response getFileContent(@RequestParam("projectId") int projectId, @RequestParam("branch") String branch,
-                                   @RequestParam("path") String path) {
-        try{
-            return Response.buildSuccess(fileReviewService.getFile(projectId, branch, path));
-        } catch (SeecoderGitlabException exception) {
-            return Response.buildFailure(500, exception.getMessage());
-        }
+                                   @RequestParam("path") String path) throws ServiceException {
+        return Response.buildSuccess(fileReviewService.getFile(projectId, branch, path));
     }
 
     @PutMapping("/inspect")

+ 5 - 17
web/src/main/java/cn/seecoder/web/controller/codereview/CommentController.java

@@ -1,19 +1,15 @@
 package cn.seecoder.web.controller.codereview;
 
+import cn.seecoder.common.exceptions.ServiceException;
 import cn.seecoder.web.model.vo.Response;
 import cn.seecoder.web.model.vo.codereview.CommentCreateVO;
-import cn.seecoder.web.model.vo.codereview.CommentVO;
 import cn.seecoder.web.service.codereview.CommentService;
-import com.nju.edu.gitlab.SeecoderGitlabException;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
-import java.io.IOException;
-import java.util.List;
-
 /**
  * @author Zihe Chen
  * @date 2022/1/12
@@ -33,23 +29,15 @@ public class CommentController {
     @GetMapping("/{codeReviewId}")
     @ApiOperation(value = "获取一个CodeReview的所有评论", httpMethod = "GET")
     @ApiImplicitParam(value = "codeReviewId", dataType = "int", paramType = "query")
-    public Response list(@PathVariable("codeReviewId") Integer codeReviewId){
-        try{
-            return Response.buildSuccess(commentService.list(codeReviewId, false));
-        } catch (SeecoderGitlabException exception) {
-            return Response.buildFailure(500, exception.getMessage());
-        }
+    public Response list(@PathVariable("codeReviewId") Integer codeReviewId) throws ServiceException {
+        return Response.buildSuccess(commentService.list(codeReviewId, false));
     }
 
     @GetMapping("/listForFileReview/{fileReviewId}")
     @ApiOperation(value = "获取文件评审的所有评论", httpMethod = "GET")
     @ApiImplicitParam(value = "fileReview", dataType = "int", paramType = "query")
-    public Response listForFileReview(@PathVariable("fileReviewId") Integer fileReviewId) {
-        try{
-            return Response.buildSuccess(commentService.list(fileReviewId, true));
-        } catch (SeecoderGitlabException exception) {
-            return Response.buildFailure(500, exception.getMessage());
-        }
+    public Response listForFileReview(@PathVariable("fileReviewId") Integer fileReviewId) throws ServiceException {
+        return Response.buildSuccess(commentService.list(fileReviewId, true));
     }
 
     @PostMapping("/create")

+ 5 - 8
web/src/main/java/cn/seecoder/web/service/codereview/BranchReviewService.java

@@ -1,15 +1,12 @@
 package cn.seecoder.web.service.codereview;
 
+import cn.seecoder.common.exceptions.ServiceException;
 import cn.seecoder.web.model.vo.codereview.CodeReviewCreateVO;
 import cn.seecoder.web.model.vo.codereview.CodeReviewSortedList;
 import cn.seecoder.web.model.vo.codereview.CodeReviewVO;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.nju.edu.gitlab.SeecoderGitlabException;
 import com.nju.edu.gitlab.vo.BranchVO;
 import com.nju.edu.gitlab.vo.DiffVO;
-import org.gitlab4j.api.GitLabApiException;
 
-import java.io.IOException;
 import java.util.List;
 import java.util.Set;
 
@@ -22,7 +19,7 @@ public interface BranchReviewService {
 
     CodeReviewSortedList list(int projectId);
 
-    void create(CodeReviewCreateVO codeReviewCreateVO) throws RuntimeException;
+    void create(CodeReviewCreateVO codeReviewCreateVO) throws ServiceException;
 
     CodeReviewVO getById(int id);
 
@@ -30,9 +27,9 @@ public interface BranchReviewService {
 
     void reopen(int id);
 
-    void merge(int id) throws GitLabApiException, SeecoderGitlabException;
+    void merge(int id) throws ServiceException;
 
-    List<BranchVO> getBranches(int projectId) throws SeecoderGitlabException;
+    List<BranchVO> getBranches(int projectId) throws ServiceException;
 
-    Set<DiffVO> compareBranches(int projectId, String fromBash, String toBash) throws SeecoderGitlabException;
+    Set<DiffVO> compareBranches(int projectId, String fromBash, String toBash) throws ServiceException;
 }

+ 2 - 2
web/src/main/java/cn/seecoder/web/service/codereview/CommentService.java

@@ -1,8 +1,8 @@
 package cn.seecoder.web.service.codereview;
 
+import cn.seecoder.common.exceptions.ServiceException;
 import cn.seecoder.web.model.vo.codereview.CommentCreateVO;
 import cn.seecoder.web.model.vo.codereview.CommentVO;
-import com.nju.edu.gitlab.SeecoderGitlabException;
 
 import java.util.List;
 
@@ -13,7 +13,7 @@ import java.util.List;
  */
 public interface CommentService {
 
-    List<CommentVO> list(int codeReviewId, boolean isFileReview) throws SeecoderGitlabException;
+    List<CommentVO> list(int codeReviewId, boolean isFileReview) throws ServiceException;
 
     void create(CommentCreateVO commentCreateVO, boolean isFileReview);
 }

+ 2 - 4
web/src/main/java/cn/seecoder/web/service/codereview/FileReviewService.java

@@ -6,8 +6,6 @@ import cn.seecoder.web.model.vo.codereview.FileNodeVO;
 import cn.seecoder.web.model.vo.codereview.FileReviewCreateVO;
 import cn.seecoder.web.model.vo.codereview.FileReviewVO;
 import cn.seecoder.web.model.vo.user.UserVO;
-import com.nju.edu.gitlab.SeecoderGitlabException;
-import java.io.IOException;
 import java.util.List;
 
 /**
@@ -23,9 +21,9 @@ public interface FileReviewService {
 
     FileReviewVO getById(int id);
 
-    String getFile(int projectId, String branch, String path) throws SeecoderGitlabException;
+    String getFile(int projectId, String branch, String path) throws ServiceException;
 
-    List<FileNodeVO> getRepositoryTree(int projectId, String branch, String... path) throws SeecoderGitlabException;
+    List<FileNodeVO> getRepositoryTree(int projectId, String branch, String... path) throws ServiceException;
 
     UserVO inviteUser(String phoneNumber) throws ServiceException;
 

+ 22 - 22
web/src/main/java/cn/seecoder/web/service/impl/codereview/BranchReviewServiceImpl.java

@@ -1,5 +1,6 @@
 package cn.seecoder.web.service.impl.codereview;
 
+import cn.seecoder.common.exceptions.ServiceException;
 import cn.seecoder.web.dao.codereview.BranchReviewMapper;
 import cn.seecoder.web.model.enums.CodeReviewStatusEnum;
 import cn.seecoder.web.model.enums.CommentTypeEnum;
@@ -12,29 +13,18 @@ import cn.seecoder.web.service.codereview.CommentService;
 import cn.seecoder.web.service.codereview.FileReviewService;
 import cn.seecoder.web.service.message.MessageService;
 import cn.seecoder.web.service.user.UserService;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
 import com.nju.edu.gitlab.SeecoderGitlabApi;
 import com.nju.edu.gitlab.SeecoderGitlabException;
 import com.nju.edu.gitlab.vo.BranchVO;
 import com.nju.edu.gitlab.vo.DiffVO;
 import lombok.extern.slf4j.Slf4j;
-import okhttp3.*;
-import org.gitlab4j.api.GitLabApi;
-import org.gitlab4j.api.GitLabApiException;
-import org.gitlab4j.api.models.MergeRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
-import java.io.IOException;
 import java.sql.Timestamp;
 import java.util.List;
 import java.util.Set;
-import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -50,7 +40,6 @@ public class BranchReviewServiceImpl implements BranchReviewService {
     private final FileReviewService fileReviewService;
     private final CommentService commentService;
     private final SeecoderGitlabApi seecoderGitlabApi;
-    private OkHttpClient client;
 
     @Autowired
     public BranchReviewServiceImpl(BranchReviewMapper branchReviewMapper, MessageService messageService, FileReviewService fileReviewService,
@@ -60,7 +49,6 @@ public class BranchReviewServiceImpl implements BranchReviewService {
         this.fileReviewService = fileReviewService;
         this.commentService = commentService;
         this.seecoderGitlabApi = seecoderGitlabApi;
-        client =  (new OkHttpClient.Builder()).connectTimeout(60L, TimeUnit.SECONDS).writeTimeout(60L, TimeUnit.SECONDS).retryOnConnectionFailure(true).build();
     }
 
     @Override
@@ -77,13 +65,13 @@ public class BranchReviewServiceImpl implements BranchReviewService {
     }
 
     @Override
-    public void create(CodeReviewCreateVO codeReviewCreateVO) throws RuntimeException {
+    public void create(CodeReviewCreateVO codeReviewCreateVO) throws ServiceException {
         CodeReviewPO codeReviewPO = new CodeReviewPO();
         BeanUtils.copyProperties(codeReviewCreateVO, codeReviewPO);
         List<CodeReviewPO> openedList = branchReviewMapper.selectOpenedReviews(codeReviewCreateVO.getProjectId());
         for(CodeReviewPO temp : openedList) {
             if(temp.getTargetBranch().equals(codeReviewCreateVO.getTargetBranch()) && temp.getSourceBranch().equals(codeReviewCreateVO.getSourceBranch())) {
-                throw new RuntimeException("已存在相同的代码评审任务,无法创建");
+                throw new ServiceException("已存在相同的代码评审任务,无法创建");
             }
         }
         codeReviewPO.setStatus(CodeReviewStatusEnum.OPENED);
@@ -143,11 +131,15 @@ public class BranchReviewServiceImpl implements BranchReviewService {
     }
 
     @Override
-    public void merge(int id) throws GitLabApiException, SeecoderGitlabException {
+    public void merge(int id) throws ServiceException {
         UserPO currentUser = UserService.loginUser();
         CodeReviewPO codeReviewPO = branchReviewMapper.selectById(id);
-        seecoderGitlabApi.mergeBranch(codeReviewPO.getProjectId(), codeReviewPO.getSourceBranch(), codeReviewPO.getTargetBranch(),
-                codeReviewPO.getTitle(), codeReviewPO.getDescription(), codeReviewPO.getReviewerId());
+        try {
+            seecoderGitlabApi.mergeBranch(codeReviewPO.getProjectId(), codeReviewPO.getSourceBranch(), codeReviewPO.getTargetBranch(),
+                    codeReviewPO.getTitle(), codeReviewPO.getDescription(), codeReviewPO.getReviewerId());
+        } catch (SeecoderGitlabException e) {
+            throw new ServiceException("合并代码评审失败", e);
+        }
         //数据库操作与对应的评论和消息创建
         branchReviewMapper.merge(id);
         CodeReviewVO codeReviewVO = this.getById(id);
@@ -167,18 +159,26 @@ public class BranchReviewServiceImpl implements BranchReviewService {
     }
 
     @Override
-    public List<BranchVO> getBranches(int projectId) throws SeecoderGitlabException {
-        return seecoderGitlabApi.getProjectBranches(projectId);
+    public List<BranchVO> getBranches(int projectId) throws ServiceException {
+        try {
+            return seecoderGitlabApi.getProjectBranches(projectId);
+        } catch (SeecoderGitlabException e) {
+            throw new ServiceException("获取分支列表失败", e);
+        }
     }
 
     @Override
-    public Set<DiffVO> compareBranches(int projectId, String fromBash, String toBash) throws SeecoderGitlabException {
+    public Set<DiffVO> compareBranches(int projectId, String fromBash, String toBash) throws ServiceException {
 //        ObjectMapper objectMapper = new ObjectMapper();
 //        Request request = new Request.Builder().url("https://seecoder-gitlab-server.seec.seecoder.cn/api/project/compare?projectId="+projectId+
 //                "&fromBash="+fromBash+"&toBash="+toBash).build();
 //        Response response = client.newCall(request).execute();
 //        return objectMapper.readTree(response.body().string());
         log.info("Compare Branch, fromBash : {}, toBash: {}", fromBash, toBash);
-        return seecoderGitlabApi.compare(projectId, fromBash, toBash);
+        try {
+            return seecoderGitlabApi.compare(projectId, fromBash, toBash);
+        } catch (SeecoderGitlabException e) {
+            throw new ServiceException("比较分支失败", e);
+        }
     }
 }

+ 8 - 2
web/src/main/java/cn/seecoder/web/service/impl/codereview/CommentServiceImpl.java

@@ -1,5 +1,6 @@
 package cn.seecoder.web.service.impl.codereview;
 
+import cn.seecoder.common.exceptions.ServiceException;
 import cn.seecoder.web.dao.codereview.BranchReviewMapper;
 import cn.seecoder.web.dao.codereview.CommentMapper;
 import cn.seecoder.web.model.enums.CommentTypeEnum;
@@ -45,12 +46,17 @@ public class CommentServiceImpl implements CommentService {
     }
 
     @Override
-    public List<CommentVO> list(int codeReviewId, boolean isFileReview) throws SeecoderGitlabException {
+    public List<CommentVO> list(int codeReviewId, boolean isFileReview) throws ServiceException {
         List<CommentVO> result = commentMapper.selectByFileReviewId(codeReviewId).stream().map(item -> new CommentVO(item)).collect(Collectors.toList());
         if(!isFileReview){
             result = commentMapper.selectByBranchReviewId(codeReviewId).stream().map(item -> new CommentVO(item)).collect(Collectors.toList());
             CodeReviewPO codeReviewPO = branchReviewMapper.selectById(codeReviewId);
-            List<CommitVO> commits = seecoderGitlabApi.getCommitsByBranch(codeReviewPO.getProjectId(), codeReviewPO.getSourceBranch());
+            List<CommitVO> commits;
+            try {
+                commits = seecoderGitlabApi.getCommitsByBranch(codeReviewPO.getProjectId(), codeReviewPO.getSourceBranch());
+            } catch (SeecoderGitlabException e) {
+                throw new ServiceException("获取分支提交失败", e);
+            }
             List<CommentVO> commitComment = commits.stream()
                     .map(item -> new CommentVO(item))
                     .filter(comment -> comment.getTime().after(codeReviewPO.getCreateTime()))

+ 13 - 17
web/src/main/java/cn/seecoder/web/service/impl/codereview/FileReviewServiceImpl.java

@@ -7,7 +7,6 @@ import cn.seecoder.web.dao.user.UserMapper;
 import cn.seecoder.web.model.enums.FileReviewStatusEnum;
 import cn.seecoder.web.model.po.codereview.FileReviewPO;
 import cn.seecoder.web.model.po.codereview.InspectionResultPO;
-import cn.seecoder.web.model.vo.codereview.FileNodeCreateVO;
 import cn.seecoder.web.model.vo.codereview.FileNodeVO;
 import cn.seecoder.web.model.vo.codereview.FileReviewCreateVO;
 import cn.seecoder.web.model.vo.codereview.FileReviewVO;
@@ -15,24 +14,14 @@ import cn.seecoder.web.model.vo.message.MessageCreateVO;
 import cn.seecoder.web.model.vo.user.UserVO;
 import cn.seecoder.web.service.codereview.FileReviewService;
 import cn.seecoder.web.service.message.MessageService;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
 import com.nju.edu.gitlab.SeecoderGitlabApi;
 import com.nju.edu.gitlab.SeecoderGitlabException;
-import jnr.ffi.annotations.In;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.Response;
 import org.apache.http.HttpStatus;
-import org.gitlab4j.api.GitLabApi;
 import org.gitlab4j.api.models.TreeItem;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.io.IOException;
 import java.util.List;
-import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 @Service
@@ -42,7 +31,6 @@ public class FileReviewServiceImpl implements FileReviewService {
     private final MessageService messageService;
     private final UserMapper userMapper;
     private final InspectionResultMapper inspectionResultMapper;
-    private OkHttpClient httpClient;
 
     @Autowired
     public FileReviewServiceImpl(SeecoderGitlabApi seecoderGitlabApi, FileReviewMapper fileReviewMapper,
@@ -52,7 +40,6 @@ public class FileReviewServiceImpl implements FileReviewService {
         this.messageService = messageService;
         this.userMapper = userMapper;
         this.inspectionResultMapper = inspectionResultMapper;
-        httpClient =  (new OkHttpClient.Builder()).connectTimeout(60L, TimeUnit.SECONDS).writeTimeout(60L, TimeUnit.SECONDS).retryOnConnectionFailure(true).build();
     }
 
     @Override
@@ -82,12 +69,16 @@ public class FileReviewServiceImpl implements FileReviewService {
     }
 
     @Override
-    public String getFile(int projectId, String branch, String path) throws SeecoderGitlabException {
-        return seecoderGitlabApi.getProjectFile(projectId, branch, path);
+    public String getFile(int projectId, String branch, String path) throws ServiceException {
+        try {
+            return seecoderGitlabApi.getProjectFile(projectId, branch, path);
+        } catch (SeecoderGitlabException e) {
+            throw new ServiceException("获取文件内容失败", e);
+        }
     }
 
     @Override
-    public List<FileNodeVO> getRepositoryTree(int projectId, String branch, String... path) throws SeecoderGitlabException {
+    public List<FileNodeVO> getRepositoryTree(int projectId, String branch, String... path) throws ServiceException {
 //        ObjectMapper objectMapper = new ObjectMapper();
 //        StringBuilder stringBuilder = new StringBuilder("https://seecoder-gitlab-gitlab.seec.seecoder.cn/api/v4/projects/")
 //                .append(projectId)
@@ -105,7 +96,12 @@ public class FileReviewServiceImpl implements FileReviewService {
 
         String filePath = "/";
         if (path.length > 0) filePath = path[0];
-        List<TreeItem> result = seecoderGitlabApi.getRepositoryTree(projectId, filePath, branch);
+        List<TreeItem> result;
+        try {
+            result = seecoderGitlabApi.getRepositoryTree(projectId, filePath, branch);
+        } catch (SeecoderGitlabException e) {
+            throw new ServiceException("获取仓库文件列表失败", e);
+        }
         return result.stream().map(item -> new FileNodeVO(item)).collect(Collectors.toList());
     }