refactor: show cloudflare analytics errors in dashboard
This commit is contained in:
@@ -37,7 +37,7 @@ import {
|
||||
export const AnalyticsView = () => {
|
||||
const [eventNames, setEventNames] = useState<string[]>([]);
|
||||
const [featureIds, setFeatureIds] = useState<string[]>([]);
|
||||
const [clickHouseDisabled, setClickHouseDisabled] = useState(false);
|
||||
const [analyticsUnavailable, setAnalyticsUnavailable] = useState(false);
|
||||
const [hasCleared, setHasCleared] = useState(false);
|
||||
const [groupFilter, setGroupFilter] = useState<string | null>(null);
|
||||
const [planDeselected, setPlanDeselected] = useState<Set<string>>(new Set());
|
||||
@@ -267,18 +267,20 @@ export const AnalyticsView = () => {
|
||||
}, [chartData, chartConfig, groupBy, responseEventNames, totals]);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
(
|
||||
error as {
|
||||
response?: {
|
||||
data?: {
|
||||
code?: string;
|
||||
};
|
||||
const code = (
|
||||
error as {
|
||||
response?: {
|
||||
data?: {
|
||||
code?: string;
|
||||
};
|
||||
}
|
||||
)?.response?.data?.code === ErrCode.TinybirdDisabled
|
||||
};
|
||||
}
|
||||
)?.response?.data?.code;
|
||||
if (
|
||||
code === ErrCode.CloudflareAnalyticsUnavailable ||
|
||||
code === ErrCode.CloudflareAnalyticsUnsupportedQuery
|
||||
) {
|
||||
setClickHouseDisabled(true);
|
||||
setAnalyticsUnavailable(true);
|
||||
}
|
||||
}, [error]);
|
||||
|
||||
@@ -320,10 +322,10 @@ export const AnalyticsView = () => {
|
||||
],
|
||||
);
|
||||
|
||||
if (clickHouseDisabled) {
|
||||
if (analyticsUnavailable) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center h-full">
|
||||
<h3 className="text-sm text-muted-foreground font-bold">Tinybird is disabled</h3>
|
||||
<h3 className="text-sm text-muted-foreground font-bold">Analytics data is unavailable</h3>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
const source = readFileSync(
|
||||
join(
|
||||
import.meta.dir,
|
||||
"../../../../../src/views/customers/customer/analytics/AnalyticsView.tsx",
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
describe("AnalyticsView error source", () => {
|
||||
test("does not expose Tinybird disabled UI", () => {
|
||||
expect(source).not.toContain("Tinybird is disabled");
|
||||
expect(source).not.toContain("ErrCode.TinybirdDisabled");
|
||||
expect(source).not.toContain("clickHouseDisabled");
|
||||
});
|
||||
|
||||
test("handles Cloudflare analytics availability errors", () => {
|
||||
expect(source).toContain("ErrCode.CloudflareAnalyticsUnavailable");
|
||||
expect(source).toContain("ErrCode.CloudflareAnalyticsUnsupportedQuery");
|
||||
expect(source).toContain("Analytics data is unavailable");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user