Skip to content

Commit 41a94c6

Browse files
committed
Show an error box if we couldn't fetch details about the instance
1 parent 004a569 commit 41a94c6

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

resources/scripts/components/dashboard/ServerRow.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,17 @@ const isAlarmState = (current: number, limit: number): boolean => {
2323
export default ({ server, className }: { server: Server; className: string | undefined }) => {
2424
const interval = useRef<number>(null);
2525
const [ stats, setStats ] = useState<ServerStats | null>(null);
26+
const [ statsError, setStatsError ] = useState(false);
2627

27-
const getStats = () => getServerResourceUsage(server.uuid).then(data => setStats(data));
28+
const getStats = () => {
29+
setStatsError(false);
30+
return getServerResourceUsage(server.uuid)
31+
.then(data => setStats(data))
32+
.catch(error => {
33+
setStatsError(true);
34+
console.error(error);
35+
});
36+
};
2837

2938
useEffect(() => {
3039
getStats().then(() => {
@@ -66,7 +75,14 @@ export default ({ server, className }: { server: Server; className: string | und
6675
</div>
6776
<div className={'w-1/3 flex items-baseline relative'}>
6877
{!stats ?
69-
<SpinnerOverlay size={'tiny'} visible={true} backgroundOpacity={0.25}/>
78+
!statsError ?
79+
<SpinnerOverlay size={'tiny'} visible={true} backgroundOpacity={0.25}/>
80+
:
81+
<div className={'flex-1 text-center'}>
82+
<span className={'bg-red-500 rounded px-2 py-1 text-red-100 text-xs'}>
83+
Connection Error
84+
</span>
85+
</div>
7086
:
7187
<React.Fragment>
7288
<div className={'flex-1 flex ml-4 justify-center'}>

0 commit comments

Comments
 (0)