From 6c668e4f863b51c8f15878c3ddd822730496337b Mon Sep 17 00:00:00 2001 From: tdurieux Date: Mon, 6 Sep 2021 23:06:10 +0200 Subject: [PATCH] fix: improve error handling when a commit is not accessible --- public/i18n/locale-en.json | 2 +- public/script/app.js | 5 +++-- src/source/GitHubStream.ts | 19 +++++++++++++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/public/i18n/locale-en.json b/public/i18n/locale-en.json index 9bf6769..1963331 100644 --- a/public/i18n/locale-en.json +++ b/public/i18n/locale-en.json @@ -1,7 +1,7 @@ { "ERRORS": { "repo_not_found": "The repository is not found.", - "repo_not_accessible": "Anonymous GitHub does not have the permission to access the repository.", + "repo_not_accessible": "Anonymous GitHub is unable to or is forbidden to access the repository.", "repository_expired": "The repository is expired", "repository_not_ready": "Anonymous GitHub is still processing the repository, it can take several minutes.", "repo_is_updating": "Anonymous GitHub is still processing the repository, it can take several minutes.", diff --git a/public/script/app.js b/public/script/app.js index 217d238..6cf02b8 100644 --- a/public/script/app.js +++ b/public/script/app.js @@ -1190,8 +1190,9 @@ angular } }, (err) => { - console.log(err); - $scope.files = []; + $scope.type = "error"; + $scope.content = err.data.error; + $scope.files = null; } ); } diff --git a/src/source/GitHubStream.ts b/src/source/GitHubStream.ts index 32801ee..2c42a1c 100644 --- a/src/source/GitHubStream.ts +++ b/src/source/GitHubStream.ts @@ -72,12 +72,19 @@ export default class GitHubStream extends GitHubBase implements SourceBase { const octokit = new Octokit({ auth: await this.getToken(), }); - const ghRes = await octokit.git.getTree({ - owner: this.githubRepository.owner, - repo: this.githubRepository.repo, - tree_sha: sha, - recursive: "1", - }); + + let ghRes; + + try { + ghRes = await octokit.git.getTree({ + owner: this.githubRepository.owner, + repo: this.githubRepository.repo, + tree_sha: sha, + recursive: "1", + }); + } catch (error) { + throw new AnonymousError("repo_not_accessible", this.repository); + } const tree = this.tree2Tree(ghRes.data.tree, truncatedTree, parentPath); if (ghRes.data.truncated) {