Skip to content

Commit fccad93

Browse files
committed
Standardize error handling and empty states for value lists
1 parent edd838d commit fccad93

File tree

4 files changed

+70
-36
lines changed

4 files changed

+70
-36
lines changed

src/treeViews/settings/environmentSecretsNode.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@ export class EnvironmentSecretsNode extends vscode.TreeItem {
1212
}
1313

1414
async getSecrets(): Promise<(SecretNode | EmptyNode)[]> {
15-
const secrets = await this.gitHubRepoContext.client.paginate(
16-
this.gitHubRepoContext.client.actions.listEnvironmentSecrets,
17-
{
18-
repository_id: this.gitHubRepoContext.id,
19-
environment_name: this.environment.name,
20-
per_page: 100
21-
},
22-
response => response.data.map(s => new SecretNode(this.gitHubRepoContext, s, this.environment))
23-
);
15+
let secrets: SecretNode[] = [];
16+
try {
17+
secrets = await this.gitHubRepoContext.client.paginate(
18+
this.gitHubRepoContext.client.actions.listEnvironmentSecrets,
19+
{
20+
repository_id: this.gitHubRepoContext.id,
21+
environment_name: this.environment.name,
22+
per_page: 100
23+
},
24+
response => response.data.map(s => new SecretNode(this.gitHubRepoContext, s, this.environment))
25+
);
26+
} catch (e) {
27+
await vscode.window.showErrorMessage((e as Error).message);
28+
}
2429

2530
if (!secrets || secrets.length === 0) {
2631
return [new EmptyNode("No environment secrets defined")];

src/treeViews/settings/environmentVariablesNode.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@ export class EnvironmentVariablesNode extends vscode.TreeItem {
1616
}
1717

1818
async getVariables(): Promise<(VariableNode | EmptyNode)[]> {
19-
const variables = await this.gitHubRepoContext.client.paginate(
20-
this.gitHubRepoContext.client.actions.listEnvironmentVariables,
21-
{
22-
repository_id: this.gitHubRepoContext.id,
23-
environment_name: this.environment.name,
24-
per_page: 100
25-
},
26-
response => response.data.map(v => new VariableNode(this.gitHubRepoContext, v, this.environment))
27-
);
19+
let variables: VariableNode[] = [];
20+
try {
21+
variables = await this.gitHubRepoContext.client.paginate(
22+
this.gitHubRepoContext.client.actions.listEnvironmentVariables,
23+
{
24+
repository_id: this.gitHubRepoContext.id,
25+
environment_name: this.environment.name,
26+
per_page: 100
27+
},
28+
response => response.data.map(v => new VariableNode(this.gitHubRepoContext, v, this.environment))
29+
);
30+
} catch (e) {
31+
await vscode.window.showErrorMessage((e as Error).message);
32+
}
2833

2934
if (!variables || variables.length === 0) {
3035
return [new EmptyNode("No environment variables defined")];
Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode";
22
import {GitHubRepoContext} from "../../git/repository";
3+
import {EmptyNode} from "./emptyNode";
34
import {SecretNode} from "./secretNode";
45

56
export class RepoSecretsNode extends vscode.TreeItem {
@@ -10,14 +11,25 @@ export class RepoSecretsNode extends vscode.TreeItem {
1011
}
1112

1213
async getSecrets(): Promise<vscode.TreeItem[]> {
13-
return await this.gitHubRepoContext.client.paginate(
14-
this.gitHubRepoContext.client.actions.listRepoSecrets,
15-
{
16-
owner: this.gitHubRepoContext.owner,
17-
repo: this.gitHubRepoContext.name,
18-
per_page: 100
19-
},
20-
response => response.data.map(s => new SecretNode(this.gitHubRepoContext, s))
21-
);
14+
let secrets: SecretNode[] = [];
15+
try {
16+
secrets = await this.gitHubRepoContext.client.paginate(
17+
this.gitHubRepoContext.client.actions.listRepoSecrets,
18+
{
19+
owner: this.gitHubRepoContext.owner,
20+
repo: this.gitHubRepoContext.name,
21+
per_page: 100
22+
},
23+
response => response.data.map(s => new SecretNode(this.gitHubRepoContext, s))
24+
);
25+
} catch (e) {
26+
await vscode.window.showErrorMessage((e as Error).message);
27+
}
28+
29+
if (!secrets || secrets.length === 0) {
30+
return [new EmptyNode("No repository secrets defined")];
31+
}
32+
33+
return secrets;
2234
}
2335
}
Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode";
22
import {GitHubRepoContext} from "../../git/repository";
3+
import {EmptyNode} from "./emptyNode";
34
import {VariableNode} from "./variableNode";
45

56
export type RepoVariablesCommandArgs = Pick<RepoVariablesNode, "gitHubRepoContext">;
@@ -12,14 +13,25 @@ export class RepoVariablesNode extends vscode.TreeItem {
1213
}
1314

1415
async getVariables(): Promise<vscode.TreeItem[]> {
15-
return await this.gitHubRepoContext.client.paginate(
16-
this.gitHubRepoContext.client.actions.listRepoVariables,
17-
{
18-
owner: this.gitHubRepoContext.owner,
19-
repo: this.gitHubRepoContext.name,
20-
per_page: 100
21-
},
22-
response => response.data.map(s => new VariableNode(this.gitHubRepoContext, s))
23-
);
16+
let variables: VariableNode[] = [];
17+
try {
18+
variables = await this.gitHubRepoContext.client.paginate(
19+
this.gitHubRepoContext.client.actions.listRepoVariables,
20+
{
21+
owner: this.gitHubRepoContext.owner,
22+
repo: this.gitHubRepoContext.name,
23+
per_page: 100
24+
},
25+
response => response.data.map(s => new VariableNode(this.gitHubRepoContext, s))
26+
);
27+
} catch (e) {
28+
await vscode.window.showErrorMessage((e as Error).message);
29+
}
30+
31+
if (!variables || variables.length === 0) {
32+
return [new EmptyNode("No repository variables defined")];
33+
}
34+
35+
return variables;
2436
}
2537
}

0 commit comments

Comments
 (0)