Skip to content

Commit

Permalink
refactor(bridge-ui): reuse timeout configuration in parseNFTMetadata (#…
Browse files Browse the repository at this point in the history
…16445)

Co-authored-by: Korbinian <[email protected]>
  • Loading branch information
ariesjia and KorbinianK committed Mar 16, 2024
1 parent 0f27341 commit 63c928c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/bridge-ui/src/libs/util/parseNFTMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { getLogger } from './logger';

const log = getLogger('libs:token:parseNFTMetadata');

const request = axios.create({ timeout: apiService.timeout });

export const parseNFTMetadata = async (token: NFT): Promise<NFTMetadata | null> => {
if (token.type !== TokenType.ERC721 && token.type !== TokenType.ERC1155) throw new Error('Not a NFT');

Expand All @@ -27,7 +29,7 @@ export const parseNFTMetadata = async (token: NFT): Promise<NFTMetadata | null>
let json;

try {
json = await axios.get(url, { timeout: apiService.timeout });
json = await request.get(url);
} catch (err) {
const error = err as AxiosError;
log(`error fetching metadata for ${token.name} id: ${token.tokenId}`, error);
Expand Down Expand Up @@ -76,7 +78,7 @@ const retry = async (url: string, tokenId: number): Promise<AxiosResponse | Erro
const retryRequest = async (newUrl: string): Promise<AxiosResponse | Error> => {
try {
log(`retrying with ${newUrl}`);
return await axios.get(newUrl);
return await request.get(newUrl);
} catch (error) {
log('retrying failed', error);
throw new Error(`No metadata found for ${newUrl}`);
Expand Down

0 comments on commit 63c928c

Please sign in to comment.