Skip to content
This repository was archived by the owner on Jun 26, 2026. It is now read-only.

Commit da6961c

Browse files
committed
chore(console): tighten error narrowing and drop redundant slice
Use 'instanceof K8sApiError' to read status from the nodes-list error instead of the previous 'as unknown as { status?: unknown }' bridge — the runtime check is type-safe and the cast is gone. K8sApiError is the only error shape the client throws on HTTP failures, and the exported class is already part of the @cozystack/k8s-client public surface. Drop the .slice() before .sort() in the per-node table: Array.filter() already returns a fresh array, so .slice() was a no-op safeguard. The chained form (.filter().sort()) is what the rest of the codebase uses when the input is known to be filter-produced. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent e229064 commit da6961c

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

‎apps/console/src/components/cluster-usage/ClusterUsageTable.tsx‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,13 @@ export function ClusterUsageTable({
205205
)
206206
}
207207

208-
const visibleRows = useMemo(() => {
209-
const filtered = rows.filter((r) => matchesFilter(r, filter))
210-
return filtered.slice().sort((a, b) => compareRows(a, b, sort))
211-
}, [rows, sort, filter])
208+
const visibleRows = useMemo(
209+
() =>
210+
rows
211+
.filter((r) => matchesFilter(r, filter))
212+
.sort((a, b) => compareRows(a, b, sort)),
213+
[rows, sort, filter],
214+
)
212215

213216
return (
214217
<div className="space-y-3">

‎apps/console/src/hooks/useClusterUsageData.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useMemo } from "react"
22
import {
33
useK8sList,
44
useApiGroupAvailable,
5+
K8sApiError,
56
type K8sList,
67
} from "@cozystack/k8s-client"
78
import { aggregateNodeResources } from "../lib/cluster-usage/aggregate.ts"
@@ -133,9 +134,7 @@ export function useClusterUsageData(): ClusterUsageData {
133134
}, [perNode])
134135

135136
const nodesError = (nodesQuery.error as Error | null) ?? null
136-
const statusField =
137-
nodesError != null ? (nodesError as unknown as { status?: unknown }).status : undefined
138-
const errorStatus = typeof statusField === "number" ? statusField : null
137+
const errorStatus = nodesError instanceof K8sApiError ? nodesError.status : null
139138

140139
return {
141140
nodes,

0 commit comments

Comments
 (0)