Skip to content

Commit

Permalink
Merge pull request #231 from bnb-chain/feat/tokenApi1216
Browse files Browse the repository at this point in the history
feat: Api error handler
  • Loading branch information
Halibao-Lala authored Dec 30, 2024
2 parents 0f97cdd + 68de75d commit 302c740
Showing 1 changed file with 45 additions and 21 deletions.
66 changes: 45 additions & 21 deletions apps/canonical-bridge-server/src/shared/web3/web3.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,52 @@ export class Web3Service {
}

async getTransferConfigsForAll() {
const { data } = await this.httpService.axiosRef.get<ITransferConfigsForAll>(
`${CBRIDGE_ENDPOINT}/v2/getTransferConfigsForAll`,
);
return data;
try {
const { data } = await this.httpService.axiosRef.get<ITransferConfigsForAll>(
`${CBRIDGE_ENDPOINT}/v2/getTransferConfigsForAll`,
);
return data;
} catch (e) {
console.error(`Failed to retrieve cBridge data at ${new Date().getTime()}`, e);
return {};
}
}

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);
return { chains: [] };
}
}

async getDebridgeChainTokens(chainId: number) {
const { data } = await this.httpService.axiosRef.get<{
tokens: Record<string, IDebridgeToken>;
}>(`${DEBRIDGE_ENDPOINT}/token-list?chainId=${chainId}`);
try {
const { data } = await this.httpService.axiosRef.get<{
tokens: Record<string, IDebridgeToken>;
}>(`${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<IStargateTokenList>(
`${STARGATE_ENDPOINT}`,
);
const processedTokenList = [];
try {
const { data } = await this.httpService.axiosRef.get<IStargateTokenList>(
`${STARGATE_ENDPOINT}`,
);
const processedTokenList = [];
const v2List = data.v2;
v2List.forEach((token) => {
const chainInfo = STARGATE_CHAIN_INFO.filter(
Expand All @@ -97,17 +115,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() {
Expand Down

0 comments on commit 302c740

Please sign in to comment.