Skip to content

Commit

Permalink
Handle fetch errors when getting content
Browse files Browse the repository at this point in the history
  • Loading branch information
depsypher committed Aug 20, 2024
1 parent 8c824c7 commit 0932cec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
11 changes: 8 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions src/scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ virtualConsole.on("error", () => {
});

async function text(url: RequestInfo): Promise<string> {
const response = await fetch(url);
if (!response.ok) {
try {
const response = await fetch(url);
if (!response.ok) {
return Promise.resolve("");
}
return await response.text();
} catch {
return Promise.resolve("");
}
return await response.text();
}

function clean(input: string, length: number): string {
Expand Down

0 comments on commit 0932cec

Please sign in to comment.