Skip to content

A modern and elegant dashboard for network traffic visualization and analysis.

fix(web): surface query errors in StatsCards instead of silent no-data

luoleib3ad5becd22b
diff --git a/apps/web/components/features/stats/stats-cards.tsx b/apps/web/components/features/stats/stats-cards.tsx
index b7aadd4..0311627 100644
--- a/apps/web/components/features/stats/stats-cards.tsx
+++ b/apps/web/components/features/stats/stats-cards.tsx
@@ -1,7 +1,7 @@
"use client";
import { useRef, useEffect } from "react";
-import { Download, Upload, Globe, Activity, Server, Route } from "lucide-react";
+import { Download, Upload, Globe, Activity, Server, Route, AlertTriangle } from "lucide-react";
import { useTranslations, useLocale } from "next-intl";
import { animate, motion, useTransform, useMotionValue } from "framer-motion";
import { formatBytes, cn } from "@/lib/utils";
@@ -109,7 +109,7 @@ function AnimatedStatCard({
// ---------- Main ----------
-export function StatsCards({ data, backendStatus, isLoading }: StatsCardsProps) {
+export function StatsCards({ data, backendStatus, isLoading, error }: StatsCardsProps) {
const t = useTranslations("stats");
const locale = useLocale();
const formatCount = (n: number) => n.toLocaleString(locale);
@@ -162,6 +162,20 @@ export function StatsCards({ data, backendStatus, isLoading }: StatsCardsProps)
</div>
);
+ if (error && !isLoading) {
+ return (
+ <div
+ role="alert"
+ className="rounded-xl border border-destructive/30 bg-destructive/5 p-4 flex items-start gap-3">
+ <AlertTriangle className="w-5 h-5 text-destructive shrink-0 mt-0.5" />
+ <div className="min-w-0">
+ <p className="text-sm font-medium text-destructive">{t("loadErrorTitle")}</p>
+ <p className="text-[13px] text-muted-foreground mt-0.5 break-words">{error}</p>
+ </div>
+ </div>
+ );
+ }
+
if (isLoading) {
return (
<div className="grid gap-2.5 grid-cols-2 sm:grid-cols-3 lg:grid-cols-6">
diff --git a/apps/web/messages/en.json b/apps/web/messages/en.json
index 9277456..9ab567d 100644
--- a/apps/web/messages/en.json
+++ b/apps/web/messages/en.json
@@ -99,7 +99,8 @@
"download": "Download",
"upload": "Upload",
"tracked": "tracked",
- "unavailable": "Waiting for backend"
+ "unavailable": "Waiting for backend",
+ "loadErrorTitle": "Failed to load statistics"
},
"chart": {
"trafficHistory": "Traffic History (24h)",
diff --git a/apps/web/messages/zh.json b/apps/web/messages/zh.json
index 99a5f04..10b7689 100644
--- a/apps/web/messages/zh.json
+++ b/apps/web/messages/zh.json
@@ -99,7 +99,8 @@
"download": "下载",
"upload": "上传",
"tracked": "已追踪",
- "unavailable": "等待后端恢复"
+ "unavailable": "等待后端恢复",
+ "loadErrorTitle": "统计数据加载失败"
},
"chart": {
"trafficHistory": "流量趋势 (24小时)",