-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
29 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
import fetch from "node-fetch"; | ||
import { JSDOM } from "jsdom"; | ||
|
||
export async function getDOM(endpoint: string) { | ||
const { | ||
window: { document }, | ||
} = new JSDOM(await fetch(endpoint).then((res) => res.text())); | ||
return document; | ||
export async function getDOM(endpoint: string): Promise<Document | undefined> { | ||
let retryCount = 3; | ||
while (retryCount > 0) { | ||
try { | ||
const { | ||
window: { document }, | ||
} = new JSDOM(await fetch(endpoint).then((res) => res.text())); | ||
return document; | ||
} catch (err) { | ||
if (err.code === "ETIMEOUT") { | ||
retryCount -= 1; | ||
} else { | ||
throw err; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters