From 9827ecde21472cadfed5bb3bc18f53d8494c6988 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 30 Dec 2024 17:08:07 +1000 Subject: [PATCH 1/2] feat: Add api error handler --- .../src/shared/web3/web3.service.ts | 64 +++++++++++++------ 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/apps/canonical-bridge-server/src/shared/web3/web3.service.ts b/apps/canonical-bridge-server/src/shared/web3/web3.service.ts index b183ac3a..8b06f1f9 100644 --- a/apps/canonical-bridge-server/src/shared/web3/web3.service.ts +++ b/apps/canonical-bridge-server/src/shared/web3/web3.service.ts @@ -60,34 +60,50 @@ export class Web3Service { } async getTransferConfigsForAll() { - const { data } = await this.httpService.axiosRef.get( - `${CBRIDGE_ENDPOINT}/v2/getTransferConfigsForAll`, - ); - return data; + try { + const { data } = await this.httpService.axiosRef.get( + `${CBRIDGE_ENDPOINT}/v2/getTransferConfigsForAll`, + ); + return data; + } catch (e) { + console.error(`Failed to retrieve cBridge data at ${new Date().getTime()}`, e); + } } async getDebridgeChains() { - const { data } = await this.httpService.axiosRef.get<{ chains: IDebridgeChain[] }>( - `${DEBRIDGE_ENDPOINT}/supported-chains-info`, - ); + try { + const { data } = await this.httpService.axiosRef.get<{ chains: IDebridgeChain[] }>( + `${DEBRIDGE_ENDPOINT}/supported-chains-info`, + ); - return data; + return data; + } catch (e) { + console.error(`Failed to retrieve DeBridge chain data at ${new Date().getTime()}`, e); + } } async getDebridgeChainTokens(chainId: number) { - const { data } = await this.httpService.axiosRef.get<{ - tokens: Record; - }>(`${DEBRIDGE_ENDPOINT}/token-list?chainId=${chainId}`); + try { + const { data } = await this.httpService.axiosRef.get<{ + tokens: Record; + }>(`${DEBRIDGE_ENDPOINT}/token-list?chainId=${chainId}`); - return data; + return data; + } catch (e) { + console.error( + `Failed to retrieve DeBridge token data from ${chainId} at ${new Date().getTime()}`, + e, + ); + return { tokens: {} }; + } } async getStargateConfigs() { - const { data } = await this.httpService.axiosRef.get( - `${STARGATE_ENDPOINT}`, - ); - const processedTokenList = []; try { + const { data } = await this.httpService.axiosRef.get( + `${STARGATE_ENDPOINT}`, + ); + const processedTokenList = []; const v2List = data.v2; v2List.forEach((token) => { const chainInfo = STARGATE_CHAIN_INFO.filter( @@ -97,17 +113,23 @@ export class Web3Service { processedTokenList.push({ ...token, endpointID: chainInfo[0].endpointID }); } }); + return processedTokenList; } catch (e) { console.log(`Failed to retrieve Stargate API data at ${new Date().getTime()}`, e); + return []; } - return processedTokenList; } async getMesonConfigs() { - const { data } = await this.httpService.axiosRef.get<{ result: IMesonChain[] }>( - `${MESON_ENDPOINT}/limits`, - ); - return data; + try { + const { data } = await this.httpService.axiosRef.get<{ result: IMesonChain[] }>( + `${MESON_ENDPOINT}/limits`, + ); + return data; + } catch (e) { + console.log(`Failed to retrieve Meson API data at ${new Date().getTime()}`, e); + return []; + } } async getAssetPlatforms() { From 68de75d428c26737fb85d8065f4fc29847f91aba Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 30 Dec 2024 17:09:15 +1000 Subject: [PATCH 2/2] chore: Add error return value --- apps/canonical-bridge-server/src/shared/web3/web3.service.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/canonical-bridge-server/src/shared/web3/web3.service.ts b/apps/canonical-bridge-server/src/shared/web3/web3.service.ts index 8b06f1f9..77d4cd8c 100644 --- a/apps/canonical-bridge-server/src/shared/web3/web3.service.ts +++ b/apps/canonical-bridge-server/src/shared/web3/web3.service.ts @@ -67,6 +67,7 @@ export class Web3Service { return data; } catch (e) { console.error(`Failed to retrieve cBridge data at ${new Date().getTime()}`, e); + return {}; } } @@ -79,6 +80,7 @@ export class Web3Service { return data; } catch (e) { console.error(`Failed to retrieve DeBridge chain data at ${new Date().getTime()}`, e); + return { chains: [] }; } }