Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Api error handler #231

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading