Skip to content

Commit 0f193c2

Browse files
committed
Catching ApiException and writing to outputs
1 parent a68954f commit 0f193c2

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/ToolWindows/GHActionsToolWindow.xaml.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,13 @@ private async Task LoadDataAsync()
254254

255255
tvCurrentBranch.ItemsSource = runsList;
256256
}
257+
catch (ApiException ex)
258+
{
259+
await _pane.WriteLineAsync($"Error retrieving Workflow Runs: {ex.Message}:{ex.StatusCode}");
260+
await ex.LogAsync();
261+
}
257262
catch (Exception ex)
258263
{
259-
Console.WriteLine(ex);
260264
await ex.LogAsync();
261265
}
262266

@@ -292,6 +296,14 @@ private async Task RefreshEnvironmentsAsync(GitHubClient client)
292296
envList.Add(new() { Name = resx.NO_ENV });
293297
}
294298
}
299+
catch (ApiException ex)
300+
{
301+
if (ex.StatusCode == System.Net.HttpStatusCode.Unauthorized || ex.StatusCode == System.Net.HttpStatusCode.Forbidden)
302+
{
303+
envList.Add(new SimpleEnvironment() { Name = "Insufficient permissions to retrieve Secrets" });
304+
await ex.LogAsync(ex.Message);
305+
}
306+
}
295307
catch (Exception ex)
296308
{
297309
envList.Add(new SimpleEnvironment() { Name = "Unable to retrieve Environments, please check logs" });
@@ -309,6 +321,11 @@ private async Task RefreshWorkflowsAsync(GitHubClient client)
309321
var workflows = await client.Actions?.Workflows?.List(_repoInfo.RepoOwner, _repoInfo.RepoName);
310322
tvWorkflows.ItemsSource = workflows.Workflows;
311323
}
324+
catch (ApiException ex)
325+
{
326+
await _pane.WriteLineAsync($"Error retrieving Workflows: {ex.Message}:{ex.StatusCode}");
327+
await ex.LogAsync();
328+
}
312329
catch (Exception ex)
313330
{
314331
await ex.LogAsync();
@@ -339,8 +356,18 @@ private async Task RefreshSecretsAsync(GitHubClient client)
339356
secretList.Add(resx.NO_REPO_SECRETS);
340357
}
341358
}
359+
catch (ApiException ex)
360+
{
361+
if (ex.StatusCode == System.Net.HttpStatusCode.Unauthorized || ex.StatusCode == System.Net.HttpStatusCode.Forbidden)
362+
{
363+
await _pane.WriteLineAsync($"Error retrieving Secrets: {ex.Message}:{ex.StatusCode}");
364+
secretList.Add("Insufficient permissions to retrieve Secrets");
365+
await ex.LogAsync(ex.Message);
366+
}
367+
}
342368
catch (Exception ex)
343369
{
370+
// check to see if a permission thing
344371
secretList.Add("Unable to retrieve Secrets, please check logs");
345372
await ex.LogAsync();
346373
}

0 commit comments

Comments
 (0)