Skip to content

Commit

Permalink
Catching ApiException and writing to outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
timheuer committed Aug 8, 2023
1 parent a68954f commit 0f193c2
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/ToolWindows/GHActionsToolWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,13 @@ private async Task LoadDataAsync()

tvCurrentBranch.ItemsSource = runsList;
}
catch (ApiException ex)
{
await _pane.WriteLineAsync($"Error retrieving Workflow Runs: {ex.Message}:{ex.StatusCode}");
await ex.LogAsync();
}
catch (Exception ex)
{
Console.WriteLine(ex);
await ex.LogAsync();
}

Expand Down Expand Up @@ -292,6 +296,14 @@ private async Task RefreshEnvironmentsAsync(GitHubClient client)
envList.Add(new() { Name = resx.NO_ENV });
}
}
catch (ApiException ex)
{
if (ex.StatusCode == System.Net.HttpStatusCode.Unauthorized || ex.StatusCode == System.Net.HttpStatusCode.Forbidden)
{
envList.Add(new SimpleEnvironment() { Name = "Insufficient permissions to retrieve Secrets" });
await ex.LogAsync(ex.Message);
}
}
catch (Exception ex)
{
envList.Add(new SimpleEnvironment() { Name = "Unable to retrieve Environments, please check logs" });
Expand All @@ -309,6 +321,11 @@ private async Task RefreshWorkflowsAsync(GitHubClient client)
var workflows = await client.Actions?.Workflows?.List(_repoInfo.RepoOwner, _repoInfo.RepoName);
tvWorkflows.ItemsSource = workflows.Workflows;
}
catch (ApiException ex)
{
await _pane.WriteLineAsync($"Error retrieving Workflows: {ex.Message}:{ex.StatusCode}");
await ex.LogAsync();
}
catch (Exception ex)
{
await ex.LogAsync();
Expand Down Expand Up @@ -339,8 +356,18 @@ private async Task RefreshSecretsAsync(GitHubClient client)
secretList.Add(resx.NO_REPO_SECRETS);
}
}
catch (ApiException ex)
{
if (ex.StatusCode == System.Net.HttpStatusCode.Unauthorized || ex.StatusCode == System.Net.HttpStatusCode.Forbidden)
{
await _pane.WriteLineAsync($"Error retrieving Secrets: {ex.Message}:{ex.StatusCode}");
secretList.Add("Insufficient permissions to retrieve Secrets");
await ex.LogAsync(ex.Message);
}
}
catch (Exception ex)
{
// check to see if a permission thing
secretList.Add("Unable to retrieve Secrets, please check logs");
await ex.LogAsync();
}
Expand Down

0 comments on commit 0f193c2

Please sign in to comment.