Skip to content

Commit

Permalink
better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
LoV432 committed Nov 17, 2023
1 parent e1f494c commit e71b6e6
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use client';
import { useEffect, useState } from 'react';
import { pppoeStatusReturnType } from '@/lib/get-pppoe-status';
import type {
getPppoeStatus,
pppoeStatusReturnType
} from '@/lib/get-pppoe-status';
import { formatUpTime } from '@/lib/format-uptime';
export function DashboardCardCurrentStatus({
pppoeStatusPrerender
Expand All @@ -23,8 +26,16 @@ export function DashboardCardCurrentStatus({
const getNewPppoeStatus = fetch('/api/get-pppoe-status');
getNewPppoeStatus
.then((response) => response.json())
.then((data: pppoeStatusReturnType) => {
setPppoeStatus(data);
.then((data: Awaited<ReturnType<typeof getPppoeStatus>>) => {
if ('up' in data) {
setPppoeStatus(data);
} else {
setPppoeStatus({
up: false,
ip: '',
uptime: 0
});
}
});
}, 3000);
return () => clearInterval(interval);
Expand Down

0 comments on commit e71b6e6

Please sign in to comment.