From 63c928c163ce2c7f3cfc3f4c38ece4dbd5aee4a8 Mon Sep 17 00:00:00 2001 From: Jaap Chen Date: Sat, 16 Mar 2024 08:42:04 +0800 Subject: [PATCH] refactor(bridge-ui): reuse timeout configuration in parseNFTMetadata (#16445) Co-authored-by: Korbinian --- packages/bridge-ui/src/libs/util/parseNFTMetadata.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/bridge-ui/src/libs/util/parseNFTMetadata.ts b/packages/bridge-ui/src/libs/util/parseNFTMetadata.ts index 21cf5fcfc5..43923bcdb7 100644 --- a/packages/bridge-ui/src/libs/util/parseNFTMetadata.ts +++ b/packages/bridge-ui/src/libs/util/parseNFTMetadata.ts @@ -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 => { if (token.type !== TokenType.ERC721 && token.type !== TokenType.ERC1155) throw new Error('Not a NFT'); @@ -27,7 +29,7 @@ export const parseNFTMetadata = async (token: NFT): Promise 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); @@ -76,7 +78,7 @@ const retry = async (url: string, tokenId: number): Promise => { 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}`);