From 9b557cee54c6ea6a2ede3d2d6722773f92be9fe9 Mon Sep 17 00:00:00 2001 From: Jos Vooges | STH Date: Tue, 25 Aug 2026 01:03:04 +0200 Subject: [PATCH] Fix dashboard BigInt crash when storage fields are missing. Co-authored-by: Cursor --- apps/admin-ui/src/app/dashboard/page.tsx | 48 +++++++++++++++++------- apps/admin-ui/src/app/movies/page.tsx | 6 ++- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/apps/admin-ui/src/app/dashboard/page.tsx b/apps/admin-ui/src/app/dashboard/page.tsx index c868f19..b8a1afc 100644 --- a/apps/admin-ui/src/app/dashboard/page.tsx +++ b/apps/admin-ui/src/app/dashboard/page.tsx @@ -15,10 +15,17 @@ interface Dashboard { currentBandwidth: string; } -function formatBytes(bytes: string): string { - const n = BigInt(bytes); +function formatBytes(bytes: string | number | null | undefined): string { + if (bytes === null || bytes === undefined || bytes === "") return "0 B"; + let n: bigint; + try { + n = typeof bytes === "bigint" ? bytes : BigInt(String(bytes)); + } catch { + return "0 B"; + } const units = ["B", "KB", "MB", "GB", "TB"]; let val = Number(n); + if (!Number.isFinite(val)) return "0 B"; let i = 0; while (val >= 1024 && i < units.length - 1) { val /= 1024; @@ -30,12 +37,21 @@ function formatBytes(bytes: string): string { export default function DashboardPage() { useAuth(); const [data, setData] = useState(null); + const [error, setError] = useState(""); useEffect(() => { fetch("/api/v1/admin/dashboard", { credentials: "include" }) - .then((r) => r.json()) - .then(setData) - .catch(console.error); + .then(async (r) => { + const json = await r.json(); + if (!r.ok) { + throw new Error(json.error?.message ?? `HTTP ${r.status}`); + } + setData(json); + }) + .catch((err) => { + console.error(err); + setError(err instanceof Error ? err.message : "Laden mislukt"); + }); }, []); return ( @@ -43,42 +59,48 @@ export default function DashboardPage() {