Skip to content

Commit

Permalink
even more error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
iskakaushik committed Dec 10, 2023
1 parent 1088da6 commit 9960cb6
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions ui/app/peers/[peerName]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,31 @@ const PeerData = async ({ params: { peerName } }: DataConfigProps) => {
};

const getStatData = async () => {
const flowServiceAddr = GetFlowHttpAddressFromEnv();
try {
const flowServiceAddr = GetFlowHttpAddressFromEnv();
const response = await fetch(`${flowServiceAddr}/v1/peers/stats/${peerName}`);

const peerStats: PeerStatResponse = await fetch(
`${flowServiceAddr}/v1/peers/stats/${peerName}`
).then((res) => res.json());
if (!response.ok) {
// Handle HTTP errors
console.error(`HTTP error: Status ${response.status} while fetching stats for peer ${peerName}`);
return null; // or throw an error
}

if (peerStats.errorMessage) {
console.log(`Error fetching stats for peer ${peerName}: ${peerStats.errorMessage}`);
}
const peerStats = await response.json();
if (peerStats.errorMessage) {
console.error(`Error fetching stats for peer ${peerName}: ${peerStats.errorMessage}`);
return null; // or handle this error specifically
}

return peerStats.statData;
return peerStats.statData;
} catch (error) {
// Handle network errors
console.error(`Network error while fetching stats for peer ${peerName}: ${error}`);
return null; // or rethrow the error
}
};


const slots = await getSlotData();
const stats = await getStatData();

Expand Down

0 comments on commit 9960cb6

Please sign in to comment.