From fe3a2f8c250ed7bf25eae28e41d042165778f3a1 Mon Sep 17 00:00:00 2001 From: Ebicoglu Date: Mon, 5 Sep 2022 17:21:52 +0300 Subject: [PATCH] Give extra info when the token doesn't work --- .../Version/BranchGithubVersionProvider.cs | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/BranchGithubVersionProvider.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/BranchGithubVersionProvider.cs index 524eecb33c..cd3969a3ab 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/BranchGithubVersionProvider.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/BranchGithubVersionProvider.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Threading.Tasks; using Octokit; using Octokit.Internal; +using Volo.Abp; using Volo.Abp.DependencyInjection; namespace Volo.Docs.GitHub.Documents.Version @@ -12,10 +14,25 @@ namespace Volo.Docs.GitHub.Documents.Version { public async Task> GetVersions(string name, string repositoryName, string token) { - var client = GetGitHubClient(name, token); - var branches = await client.Repository.Branch.GetAll(name, repositoryName); + try + { + var client = GetGitHubClient(name, token); + var branches = await client.Repository.Branch.GetAll(name, repositoryName); - return branches.Select(b => new GithubVersion {Name = b.Name}).ToList(); + return branches.Select(b => new GithubVersion { Name = b.Name }).ToList(); + } + catch (Exception e) + { + var apiException = (Octokit.ApiException)e; + if (apiException.ApiError?.Message == "Bad credentials" || + apiException.StatusCode == HttpStatusCode.Unauthorized) + { + throw new AbpException("Invalid credentials for the GitHub repository: " + name + "/" + repositoryName + ". " + + "The GitHub access token: " + token + " does not work!" + "\n\rError: " + e); + } + + throw new AbpException("Could not get branches from GitHub repository: " + name + "/" + repositoryName + "\n\rError: " + e.Message); + } } private static GitHubClient GetGitHubClient(string name, string token)