aboutsummaryrefslogtreecommitdiff
path: root/src/scraper.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/scraper.ts')
-rw-r--r--src/scraper.ts12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/scraper.ts b/src/scraper.ts
index 6461b19..fb48700 100644
--- a/src/scraper.ts
+++ b/src/scraper.ts
@@ -13,16 +13,20 @@ export class GitHubHTTPError extends Error {
}
}
-export class RedirectError extends Error {
+export abstract class RedirectError extends Error {
location: string;
constructor(location: string) {
super(`Redirect to ${location}`);
- this.name = "RedirectError";
+ this.name = this.constructor.name;
this.location = location;
}
}
+export class InternalRedirectError extends RedirectError {}
+
+export class ExternalRedirectError extends RedirectError {}
+
interface TreeItem {
contentType: "directory" | "file";
name: string;
@@ -423,7 +427,7 @@ async function fetchGitHubResponse(path: string, accept: string): Promise<Respon
if (location) {
const url = new URL(location);
if (url.hostname === "github.com") {
- throw new RedirectError(url.pathname);
+ throw new InternalRedirectError(url.pathname);
}
}
}
@@ -1127,7 +1131,7 @@ export async function getGitHubOwner(owner: string): Promise<GitHubOwner> {
return parseOrganization(document, owner);
}
// Not a profile page (marketing pages like github.com/features, etc.).
- throw new RedirectError(`https://github.com/${owner}`);
+ throw new ExternalRedirectError(`https://github.com/${owner}`);
}
// The text directly inside an element, ignoring any nested elements' text.