From e71b6e624e7123fa40ef2b4f534800293b9931b5 Mon Sep 17 00:00:00 2001 From: LoV432 Date: Sat, 18 Nov 2023 00:56:00 +0500 Subject: [PATCH] better error handling --- .../DashboardCardCurrentStatus.client.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/components/dashboard/DashboardCardCurrentStatus/DashboardCardCurrentStatus.client.tsx b/app/components/dashboard/DashboardCardCurrentStatus/DashboardCardCurrentStatus.client.tsx index 937a7cd..27b7930 100644 --- a/app/components/dashboard/DashboardCardCurrentStatus/DashboardCardCurrentStatus.client.tsx +++ b/app/components/dashboard/DashboardCardCurrentStatus/DashboardCardCurrentStatus.client.tsx @@ -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 @@ -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>) => { + if ('up' in data) { + setPppoeStatus(data); + } else { + setPppoeStatus({ + up: false, + ip: '', + uptime: 0 + }); + } }); }, 3000); return () => clearInterval(interval);