Skip to content

Commit

Permalink
fail on !r.ok; filter dom errors
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Aug 18, 2023
1 parent cba3698 commit 5698072
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib/fetchPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ function buildCache() {
const getFetcher = memoize(() => fetchBuilder.withCache(buildCache()));

export default async function fetchPost(url: string): Promise<string> {
return getFetcher()(url).then((r) => r.text());
return getFetcher()(url).then((r) => {
if (!r.ok) throw new Error(`Failed to fetch ${url}`);
return r.text();
});
}
7 changes: 7 additions & 0 deletions src/lib/getDom.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Window } from "happy-dom";
import memoize from "./memoize";

const { error } = console;

console.error = (...args: unknown[]) => {
if (String(args[0]).includes("Failed to load external script")) return;
error(...args);
};

const getDom = memoize((html: string) => {
const window = new Window({
settings: {
Expand Down

0 comments on commit 5698072

Please sign in to comment.