Skip to content

Commit

Permalink
chore(retry): unify retry function
Browse files Browse the repository at this point in the history
  • Loading branch information
D4mph1r committed Sep 17, 2024
1 parent a43ac59 commit 9f73b92
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/handler/evm/utils/nftData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const nftData = (provider: JsonRpcProvider, logger: LogInstance) => {
() => nft.name(),
`Trying to fetch name() for ${contract}`,
logger,
);
5,
).catch(() => {
return "";
});

const symbol = await retry(
() => nft.symbol(),
Expand All @@ -24,9 +27,11 @@ const nftData = (provider: JsonRpcProvider, logger: LogInstance) => {
const royalty = await retry(
() => nft.royaltyInfo(tokenId, MAX_SALE_PRICE),
`Trying to fetch royaltyInfo() for ${contract}`,

logger,
);
5,
).catch(() => {
return undefined;
});

const metadata = await retry(
() => nft.tokenURI(tokenId),
Expand Down
7 changes: 7 additions & 0 deletions src/handler/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function retry<T>(
func: () => Promise<T>,
ctx: string,
log: LogInstance,
retryCount?: number,
): Promise<T> {
while (true) {
try {
Expand All @@ -53,6 +54,12 @@ export async function retry<T>(
} catch (err) {
log.info(`Context: ${ctx} - Retrying. Error:`, err);
// Use a Promise-based delay
if (retryCount) {
const Count = retryCount - 1;
if (Count <= 0) {
throw new Error(`Failed ${ctx}`);
}
}
await setTimeout(5000);
}
}
Expand Down

0 comments on commit 9f73b92

Please sign in to comment.