Skip to content

Commit

Permalink
Added more error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mvpoyatt authored and mvpoyatt committed May 22, 2024
1 parent 9b9a93c commit aa10dbe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
1 change: 0 additions & 1 deletion app/(routes)/packets/packet-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Packet, PacketStates, stateToString } from 'utils/types/packet';
import { CHAIN_CONFIGS, CHAIN, clientToDisplay } from 'utils/chains/configs';
import { classNames } from 'utils/functions';
import { CopyButton } from 'components/copy-button';
import { SimIcon } from 'components/icons';

export function PacketDetails(packet: Packet | null) {
let sourceUrl = '';
Expand Down
29 changes: 25 additions & 4 deletions app/api/packets/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@ async function processPacketRequest(packetRequest: {
body: JSON.stringify(packetRequest)
};

const packetRes = await (await fetch(process.env.INDEXER_URL!, packetOptions)).json();
let packetRes;
try {
packetRes = await (await fetch(process.env.INDEXER_URL!, packetOptions)).json();
} catch (err) {
logger.error('Error processing packet request: ' + err);
return [];
}

if (packetRes.errors) {
logger.error('Error processing packet request: ' + packetRes.errors);
return [];
}

const responseItems = packetRes?.data?.packets;
if (!responseItems) {
return [];
Expand Down Expand Up @@ -56,7 +68,6 @@ async function processPacketRequest(packetRequest: {
sourceClient: packet.sendPacket?.sourceChannel?.portId.split('.')[1],
destClient: packet.sendPacket?.sourceChannel?.counterpartyPortId.split('.')[1],
};

packets.push(newPacket);
}

Expand Down Expand Up @@ -108,7 +119,12 @@ export async function getPacket(txHash: string): Promise<Packet[]> {
variables: { txHash }
};

return await processPacketRequest(packetRequest);
try {
return await processPacketRequest(packetRequest);
} catch (err) {
logger.error(`Error finding packet packet with txHash ${txHash}: ` + err);
return [];
}
}

export async function getRecentPackets(limit: number = 1000): Promise<Packet[]> {
Expand Down Expand Up @@ -150,5 +166,10 @@ export async function getRecentPackets(limit: number = 1000): Promise<Packet[]>
variables: { limit }
};

return await processPacketRequest(packetRequest);
try {
return await processPacketRequest(packetRequest);
} catch (err) {
logger.error('Error getting recent packets: ' + err);
return [];
}
}

0 comments on commit aa10dbe

Please sign in to comment.