@@ -2,6 +2,7 @@ import { useEffect, useMemo, useState } from 'react'
22import { clsx } from 'clsx'
33import { AlertCircle , DollarSign , HelpCircle , Loader2 , TrendingUp } from 'lucide-react'
44import {
5+ ApiError ,
56 useOpenCostWorkload ,
67 useOpenCostWorkloadTrend ,
78 COST_DISCOVERY_GRACE_MS ,
@@ -40,8 +41,8 @@ type WorkloadCostState =
4041interface WorkloadCostQueryStatus {
4142 currentLoading ?: boolean
4243 trendLoading ?: boolean
43- currentError ?: boolean
44- trendError ?: boolean
44+ currentError ?: unknown
45+ trendError ?: unknown
4546}
4647
4748interface WorkloadCostTabProps {
@@ -62,8 +63,8 @@ export function WorkloadCostTab({ kind, namespace, name }: WorkloadCostTabProps)
6263 const state = getWorkloadCostState ( currentQuery . data , trendData , {
6364 currentLoading : currentQuery . isLoading ,
6465 trendLoading,
65- currentError : currentQuery . isError ,
66- trendError : trendQuery . isError ,
66+ currentError : currentQuery . error ,
67+ trendError : trendQuery . error ,
6768 } )
6869
6970 useEffect ( ( ) => {
@@ -296,15 +297,26 @@ export function getWorkloadCostState(
296297 return 'data'
297298 }
298299 if ( trendHasData ) return 'partial_missing_current'
300+ const reason =
301+ current ?. reason ??
302+ trend ?. reason ??
303+ costUnavailableReasonFromError ( queryStatus . currentError ) ??
304+ costUnavailableReasonFromError ( queryStatus . trendError )
305+ if ( reason === 'no_prometheus' || reason === 'query_error' || reason === 'access_denied' || reason === 'not_found' )
306+ return reason
299307 if ( queryError ) return 'load_error'
300308 if ( loading ) return 'loading'
301309
302- const reason = current ?. reason ?? trend ?. reason
303- if ( reason === 'no_prometheus' || reason === 'query_error' || reason === 'access_denied' || reason === 'not_found' )
304- return reason
305310 return 'no_metrics'
306311}
307312
313+ function costUnavailableReasonFromError ( error : unknown ) : CostUnavailableReason | undefined {
314+ if ( ! ( error instanceof ApiError ) ) return undefined
315+ if ( error . status === 403 ) return 'access_denied'
316+ if ( error . status === 404 ) return 'not_found'
317+ return undefined
318+ }
319+
308320function WorkloadCostDiscovering ( { isFetching, onRetry } : { isFetching : boolean ; onRetry : ( ) => void } ) {
309321 return (
310322 < div className = "flex h-full min-h-[320px] items-center justify-center" >
0 commit comments