Skip to content

Commit 83dc632

Browse files
committed
fix: issue with version-switcher.tsx
1 parent 843e5f9 commit 83dc632

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

showcases/patternhub/components/version-switcher/version-switcher.tsx

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,28 +73,33 @@ const VersionSwitcher = () => {
7373

7474
useEffect(() => {
7575
const runAsync = async () => {
76-
const branchesResponse = await fetchFromGitHubApi(
77-
`https://api.github.com/repos/${owner}/${repo}/branches`
78-
);
79-
const tagsResponse = await fetchFromGitHubApi(
80-
`https://api.github.com/repos/${owner}/${repo}/tags`
81-
);
82-
const tags: string[] = tagsResponse.map(
83-
(tag: GithubResponse) => tag.name
84-
);
85-
const branches: string[] = branchesResponse
86-
.map((branch: GithubResponse) => branch.name)
87-
.filter(
88-
(branch) =>
89-
branch !== 'gh-pages' && !branch.includes('dependabot')
76+
try {
77+
const branchesResponse = await fetchFromGitHubApi(
78+
`https://api.github.com/repos/${owner}/${repo}/branches`
9079
);
91-
92-
// `latest` isn't a branch, but only existing within gh-pages
93-
tags.unshift('latest');
94-
95-
setCurrentBranch(branches);
96-
setCurrentBranch(tags);
97-
setGroupByTagsBranches(tags, branches);
80+
const tagsResponse = await fetchFromGitHubApi(
81+
`https://api.github.com/repos/${owner}/${repo}/tags`
82+
);
83+
const tags: string[] = tagsResponse.map(
84+
(tag: GithubResponse) => tag.name
85+
);
86+
const branches: string[] = branchesResponse
87+
.map((branch: GithubResponse) => branch.name)
88+
.filter(
89+
(branch) =>
90+
branch !== 'gh-pages' &&
91+
!branch.includes('dependabot')
92+
);
93+
94+
// `latest` isn't a branch, but only existing within gh-pages
95+
tags.unshift('latest');
96+
97+
setCurrentBranch(branches);
98+
setCurrentBranch(tags);
99+
setGroupByTagsBranches(tags, branches);
100+
} catch (error: any) {
101+
console.error(error);
102+
}
98103
};
99104

100105
void runAsync();

0 commit comments

Comments
 (0)