Skip to content

Commit

Permalink
fix(scraper): retry when resp not ok
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Jan 10, 2024
1 parent a658e47 commit 79fe662
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/animegarden/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"license": "MIT",
"author": "XLor",
"sideEffects": false,
"type": "module",
"exports": {
".": {
"require": "./dist/index.cjs",
Expand Down
11 changes: 7 additions & 4 deletions packages/scraper/src/dmhy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ export async function fetchDmhyPage(
): Promise<FetchedResource[]> {
const { page = 1, retry = 5 } = options;

const resp = await retryFn(
() => ofetch(`https://share.dmhy.org/topics/list/page/${page}`),
retry
);
const resp = await retryFn(async () => {
const resp = await ofetch(`https://share.dmhy.org/topics/list/page/${page}`);
if (!resp.ok) {
throw new Error(resp.statusText, { cause: resp });
}
return resp;
}, retry);
if (!resp.ok) {
throw new Error('Failed connecting https://share.dmhy.org');
}
Expand Down

0 comments on commit 79fe662

Please sign in to comment.