aboutsummaryrefslogtreecommitdiff
path: root/src/scraper.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/scraper.ts')
-rw-r--r--src/scraper.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/scraper.ts b/src/scraper.ts
index 4feda73..b76f8c8 100644
--- a/src/scraper.ts
+++ b/src/scraper.ts
@@ -1,3 +1,13 @@
+export class GitHubHTTPError extends Error {
+ status: number;
+
+ constructor(status: number, message: string) {
+ super(message);
+ this.name = "GitHubHTTPError";
+ this.status = status;
+ }
+}
+
interface TreeItem {
contentType: "directory" | "file";
name: string;
@@ -78,6 +88,7 @@ async function fetchGitHubPage(path: string): Promise<string> {
"Accept-Language": "en-US,en;q=0.5",
};
const response = await fetch(`https://github.com/${path}`, { headers });
+ if (!response.ok) throw new GitHubHTTPError(response.status, response.statusText);
return response.text();
}