Skip to content

Commit

Permalink
better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
iskakaushik committed Dec 10, 2023
1 parent 753abc6 commit 1088da6
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions ui/app/peers/[peerName]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,39 @@ type DataConfigProps = {
const PeerData = async ({ params: { peerName } }: DataConfigProps) => {
const getSlotData = async () => {
const flowServiceAddr = GetFlowHttpAddressFromEnv();
try {
const response = await fetch(`${flowServiceAddr}/v1/peers/slots/${peerName}`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

const peerSlots: PeerSlotResponse = await fetch(
`${flowServiceAddr}/v1/peers/slots/${peerName}`
).then((res) => res.json());
const peerSlots: PeerSlotResponse = await response.json();
if (peerSlots.errorMessage) {
console.log(`Error fetching slots for peer ${peerName}: ${peerSlots.errorMessage}`);
}

if (peerSlots.errorMessage) {
console.log(`Error fetching slots for peer ${peerName}: ${peerSlots.errorMessage}`);
const slotArray = peerSlots.slotData;
// slots with 'peerflow_slot' should come first
slotArray?.sort((slotA, slotB) => {
if (
slotA.slotName.startsWith('peerflow_slot') &&
!slotB.slotName.startsWith('peerflow_slot')
) {
return -1;
} else if (
!slotA.slotName.startsWith('peerflow_slot') &&
slotB.slotName.startsWith('peerflow_slot')
) {
return 1;
} else {
return 0;
}
});
return slotArray;
} catch (error) {
console.error(`Error fetching slots for peer ${peerName}: ${error}`);
return null;
}

const slotArray = peerSlots.slotData;
// slots with 'peerflow_slot' should come first
slotArray?.sort((slotA, slotB) => {
if (
slotA.slotName.startsWith('peerflow_slot') &&
!slotB.slotName.startsWith('peerflow_slot')
) {
return -1;
} else if (
!slotA.slotName.startsWith('peerflow_slot') &&
slotB.slotName.startsWith('peerflow_slot')
) {
return 1;
} else {
return 0;
}
});
return slotArray;
};

const getStatData = async () => {
Expand Down

0 comments on commit 1088da6

Please sign in to comment.