Skip to content

Commit 03d24d7

Browse files
committed
fix: avoid error if we fail loading github URL
1 parent d6d17ed commit 03d24d7

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

public/js/components/home.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export class HomeView {
2727
const repoName = utils.getGithubRepositoryPath(
2828
utils.parseRepositoryUrl(repository)
2929
)
30+
if (repoName === null) {
31+
return;
32+
}
3033

3134
fetchScorecardData(repoName).then((data) => {
3235
if (data !== null) {

public/js/components/package/pannels/scorecard.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export class Scorecard {
2424
}
2525

2626
const repoName = utils.getGithubRepositoryPath(githubURL.href);
27+
if (repoName === null) {
28+
return;
29+
}
2730
const pannel = clone.getElementById("pan-scorecard");
2831
fetchScorecardData(repoName).then((data) => {
2932
if (!data) {

public/js/utils.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ import avatarURL from "../img/avatar-default.png";
44
window.activeLegendElement = null;
55

66
export function getGithubRepositoryPath(url) {
7-
const github = new URL(url);
7+
try {
8+
const github = new URL(url);
89

9-
return github.pathname.slice(
10-
1,
11-
github.pathname.includes(".git") ? -4 : github.pathname.length
12-
);
10+
return github.pathname.slice(
11+
1,
12+
github.pathname.includes(".git") ? -4 : github.pathname.length
13+
);
14+
}
15+
catch {
16+
return null;
17+
}
1318
}
1419

1520
/**

0 commit comments

Comments
 (0)